Skip to content

Commit

Permalink
Merge branch 'mraszyk/pic-fix-cert-state' into 'master'
Browse files Browse the repository at this point in the history
fix(PocketIC): executing query call on new PocketIC instance crashed PocketIC server

This MR fixes a bug in the PocketIC server that made a query call on a new PocketIC instance crash the PocketIC server. 

See merge request dfinity-lab/public/ic!20292
  • Loading branch information
mraszyk committed Jul 8, 2024
2 parents d7710fd + ac210ee commit 253a3cd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 0 additions & 4 deletions packages/pocket-ic/src/nonblocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ impl PocketIc {
/// for this instance can be made.
#[instrument(skip(self), fields(instance_id=self.instance_id))]
pub async fn make_live(&mut self, listen_at: Option<u16>) -> Url {
// Execute a tick to make sure all subnets have a certified state.
self.tick().await;
self.auto_progress().await;
self.start_http_gateway(listen_at, None, None).await
}
Expand All @@ -320,8 +318,6 @@ impl PocketIc {
domains: Option<Vec<String>>,
https_config: Option<HttpsConfig>,
) -> Url {
// Execute a tick to make sure all subnets have a certified state.
self.tick().await;
self.auto_progress().await;
self.start_http_gateway(listen_at, domains, https_config)
.await
Expand Down
16 changes: 16 additions & 0 deletions packages/pocket-ic/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,3 +1027,19 @@ fn test_xnet_call_and_create_canister_with_specified_id() {
}
}
}

#[test]
fn test_query_call_on_new_pocket_ic() {
let pic = PocketIc::new();

let topology = pic.topology();
let app_subnet = topology.get_app_subnets()[0];
let canister_id = Principal::from_slice(
&topology.0.get(&app_subnet).unwrap().canister_ranges[0]
.start
.canister_id,
);

pic.query_call(canister_id, Principal::anonymous(), "foo", vec![])
.unwrap_err();
}
3 changes: 3 additions & 0 deletions rs/pocket_ic_server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New CLI option `--ready-file` to specify a file which is created by the PocketIC server once it is ready to accept HTTP connections.
- A new endpoint `/instances/<instance_id>/_/dashboard` serving a PocketIC dashboard.

### Fixed
- Executing a query call on a new PocketIC instance crashed the PocketIC server.

## 4.0.0 - 2024-04-30

### Added
Expand Down
5 changes: 5 additions & 0 deletions rs/pocket_ic_server/src/pocket_ic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ impl PocketIc {
subnet.reload_registry();
}

// We execute a round on every subnet to make sure it has a state to certify.
for subnet in subnets.read().unwrap().values() {
subnet.execute_round();
}

Self {
subnets,
routing_table,
Expand Down

0 comments on commit 253a3cd

Please sign in to comment.