-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src/client: Implement init proceedure #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,16 +28,37 @@ pub struct Client { | |
} | ||
|
||
impl Client { | ||
pub async fn new() -> Result<(Self, RunParameters), Box<dyn std::error::Error>> { | ||
pub async fn new_and_init() -> Result<(Self, RunParameters), Box<dyn std::error::Error>> { | ||
let params = RunParameters::try_parse()?; | ||
|
||
let (cmd_tx, cmd_rx) = channel(1); | ||
|
||
let background = BackgroundTask::new(cmd_rx, params.clone()).await?; | ||
let client = Self { cmd_tx }; | ||
|
||
tokio::spawn(background.run()); | ||
|
||
Ok((Self { cmd_tx }, params)) | ||
client.wait_network_initialized().await?; | ||
|
||
let global_seq_num = client | ||
// Note that the sdk-go only signals, but not waits. | ||
.signal_and_wait("initialized_global", params.test_instance_count) | ||
.await?; | ||
|
||
let group_seq_num = client | ||
// Note that the sdk-go only signals, but not waits. | ||
.signal_and_wait( | ||
format!("initialized_group_{}", params.test_group_id), | ||
params.test_group_instance_count as u64, | ||
) | ||
.await?; | ||
|
||
client.record_message(format!( | ||
"claimed sequence numbers; global={}, group({})={}", | ||
global_seq_num, params.test_group_id, group_seq_num | ||
)); | ||
|
||
Ok((client, params)) | ||
} | ||
|
||
/// ```publish``` publishes an item on the supplied topic. | ||
|
@@ -133,7 +154,7 @@ impl Client { | |
|
||
/// ```wait_network_initialized``` waits for the sidecar to initialize the network, | ||
/// if the sidecar is enabled. | ||
pub async fn wait_network_initialized(&self) -> Result<(), Error> { | ||
async fn wait_network_initialized(&self) -> Result<(), Error> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can not think of a use-case where one would not call this method at start. Thus I am proposing to include it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't think of a case either! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// Event | ||
let (sender, receiver) = oneshot::channel(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for sharing the draft!
A couple of notes:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for exposing it to the test, though I haven't clean way to do so yet. Still want to put more thoughts into it. In my eyes this can happen as a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I can't think of a use-case where one would want to publish but not wait.