Skip to content

Commit

Permalink
Don't return error on repeated channel shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Jul 8, 2024
1 parent cc429a0 commit 6e18ed6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 33 deletions.
11 changes: 8 additions & 3 deletions src/ckb/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,16 +645,21 @@ impl<S: ChannelActorStateStore> ChannelActor<S> {
) -> ProcessingChannelResult {
debug!("Handling shutdown command: {:?}", &command);
let flags = match state.state {
ChannelState::Closed => {
debug!("Channel already closed, ignoring shutdown command");
return Ok(());
}
ChannelState::ChannelReady() => {
debug!("Handling shutdown command in ChannelReady state");
ShuttingDownFlags::empty()
}
ChannelState::ShuttingDown(flags) => flags,
_ => {
debug!("Handling shutdown command in state {:?}", &state.state);
return Err(ProcessingChannelError::InvalidState(
"Trying to send shutdown message while in invalid state".to_string(),
));
return Err(ProcessingChannelError::InvalidState(format!(
"Trying to send shutdown message while in invalid state {:?}",
&state.state
)));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ body:json {
}

assert {
res.body.error: isDefined
res.body.result: isUndefined
res.body.error: isUndefined
res.body.result: isNull
}

script:post-response {
// Sleep for sometime to make sure current operation finishes before next request starts.
// will get error message since channel is closed in previous step
await new Promise(r => setTimeout(r, 100));
if (!(res.body.error.message === "Messaging failed because channel is closed")) {
throw new Error("Assertion failed: error message is not right");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ body:json {
}

assert {
res.body.error: isDefined
res.body.result: isUndefined
}

script:post-response {
// Sleep for sometime to make sure current operation finishes before next request starts.
// will get error message since channel is closed in previous step
await new Promise(r => setTimeout(r, 100));
if (!(res.body.error.message === "Messaging failed because channel is closed")) {
throw new Error("Assertion failed: error message is not right");
}
}
res.body.error: isUndefined
res.body.result: isNull
}
15 changes: 3 additions & 12 deletions tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ body:json {
}

assert {
res.body.error: isDefined
res.body.result: isUndefined
}

script:post-response {
// Sleep for sometime to make sure current operation finishes before next request starts.
// will get error message since channel is closed in previous step
await new Promise(r => setTimeout(r, 100));
if (!(res.body.error.message === "Messaging failed because channel is closed")) {
throw new Error("Assertion failed: error message is not right");
}
}
res.body.error: isUndefined
res.body.result: isNull
}

0 comments on commit 6e18ed6

Please sign in to comment.