Skip to content

Commit 73bb326

Browse files
test(registry): Set up sharded routing table in registry tests (#5810)
Routing table format is being changed from a single value to sharded values. This PR sets up the sharded routing table in addition to the single routing table. --------- Co-authored-by: Max Summe <maximilian.summe@dfinity.org>
1 parent d08ec48 commit 73bb326

File tree

6 files changed

+31
-66
lines changed

6 files changed

+31
-66
lines changed

rs/nns/integration_tests/src/registry_get_changes_since.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn test_allow_opaque_caller() {
3838
assert_eq!(error, None);
3939
// The important thing is that deltas is not empty. The exact number of
4040
// elements is not so important.
41-
assert_eq!(deltas.len(), 13);
41+
assert_eq!(deltas.len(), 14);
4242
assert_eq!(version, 1);
4343
}
4444

@@ -70,6 +70,6 @@ fn test_allow_self_authenticating_caller() {
7070
assert_eq!(error, None);
7171
// The important thing is that deltas is not empty. The exact number of
7272
// elements is not so important.
73-
assert_eq!(deltas.len(), 13);
73+
assert_eq!(deltas.len(), 14);
7474
assert_eq!(version, 1);
7575
}

rs/nns/test_utils/src/registry.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,29 @@ pub async fn insert_value<T: Message + Default>(registry: &Canister<'_>, key: &[
286286
);
287287
}
288288

289-
pub fn routing_table_mutation(rt: &RoutingTable) -> RegistryMutation {
289+
/// Returns a list of mutations that set the initial state of the routing table.
290+
///
291+
/// Note that it's undefined behavior if they are used to modify an existing
292+
/// routing table.
293+
pub fn initial_routing_table_mutations(rt: &RoutingTable) -> Vec<RegistryMutation> {
290294
use ic_protobuf::registry::routing_table::v1 as pb;
291295

292296
let rt_pb = pb::RoutingTable::from(rt);
293297
let mut buf = vec![];
294298
rt_pb.encode(&mut buf).unwrap();
295-
RegistryMutation {
296-
mutation_type: Type::Upsert as i32,
297-
key: make_routing_table_record_key().into_bytes(),
298-
value: buf,
299-
}
299+
vec![
300+
// TODO(NNS1-3781): Remove this once routing_table is no longer used by clients.
301+
RegistryMutation {
302+
mutation_type: Type::Upsert as i32,
303+
key: make_routing_table_record_key().into_bytes(),
304+
value: buf.clone(),
305+
},
306+
RegistryMutation {
307+
mutation_type: Type::Upsert as i32,
308+
key: make_canister_ranges_key(CanisterId::from(0)).into_bytes(),
309+
value: buf,
310+
},
311+
]
300312
}
301313

302314
/// Returns a mutation that sets the initial state of the registry to be
@@ -374,7 +386,6 @@ pub fn invariant_compliant_mutation_with_subnet_id(
374386
make_subnet_record_key(subnet_pid).as_bytes(),
375387
system_subnet.encode_to_vec(),
376388
),
377-
routing_table_mutation(&RoutingTable::default()),
378389
insert(
379390
make_replica_version_key(replica_version_id).as_bytes(),
380391
replica_version.encode_to_vec(),
@@ -390,6 +401,9 @@ pub fn invariant_compliant_mutation_with_subnet_id(
390401
valid_pks,
391402
));
392403
mutations.append(&mut threshold_pk_and_cup_mutations);
404+
mutations.append(&mut initial_routing_table_mutations(
405+
&RoutingTable::default(),
406+
));
393407
mutations
394408
}
395409

rs/registry/canister/src/mutations/routing_table.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -489,57 +489,6 @@ mod tests {
489489
// GetSubnetForCanisterError::CanisterIdConversion currently not reachable - CanisterId::try_from() always succeeds
490490
}
491491

492-
#[test]
493-
fn test_routing_table_saves_as_canister_range_records_on_first_invocation_correctly() {
494-
let mut registry = invariant_compliant_registry(0);
495-
let system_subnet =
496-
PrincipalId::try_from(registry.get_subnet_list_record().subnets.first().unwrap())
497-
.unwrap();
498-
499-
let mut original = RoutingTable::new();
500-
original
501-
.insert(
502-
CanisterIdRange {
503-
start: CanisterId::from(5000),
504-
end: CanisterId::from(6000),
505-
},
506-
system_subnet.into(),
507-
)
508-
.unwrap();
509-
original
510-
.insert(
511-
CanisterIdRange {
512-
start: CanisterId::from(6001),
513-
end: CanisterId::from(7000),
514-
},
515-
system_subnet.into(),
516-
)
517-
.unwrap();
518-
519-
let new_routing_table = pb::RoutingTable::from(original.clone());
520-
let mutations = vec![upsert(
521-
make_routing_table_record_key().as_bytes(),
522-
new_routing_table.encode_to_vec(),
523-
)];
524-
registry.maybe_apply_mutation_internal(mutations);
525-
526-
let recovered = registry
527-
.get_routing_table_from_canister_range_records_or_panic(registry.latest_version());
528-
529-
assert_eq!(recovered, RoutingTable::new());
530-
531-
// Now we are in a situation where there is no difference between what's stored under the
532-
// `routing_table` key and what's being saved BUT we should still generate canister_ranges_*
533-
// records b/c they're empty
534-
let mutations = routing_table_into_registry_mutation(&registry, original.clone());
535-
registry.maybe_apply_mutation_internal(mutations);
536-
537-
let recovered = registry
538-
.get_routing_table_from_canister_range_records_or_panic(registry.latest_version());
539-
540-
assert_eq!(recovered, original);
541-
}
542-
543492
#[test]
544493
fn test_routing_table_updates_and_deletes_entries_as_expected() {
545494
let mut registry = invariant_compliant_registry(0);

rs/registry/canister/tests/modify_canister_migrations.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use ic_nns_test_utils::{
55
local_test_on_nns_subnet, set_up_registry_canister, set_up_universal_canister,
66
try_call_via_universal_canister,
77
},
8-
registry::{get_value_or_panic, prepare_registry_with_two_node_sets, routing_table_mutation},
8+
registry::{
9+
get_value_or_panic, initial_routing_table_mutations, prepare_registry_with_two_node_sets,
10+
},
911
};
1012
use ic_protobuf::registry::routing_table::v1 as pb;
1113
use ic_registry_routing_table::{CanisterIdRange, CanisterMigrations, RoutingTable};
@@ -55,7 +57,7 @@ fn test_modify_canister_migrations() {
5557
.expect("failed to update the routing table");
5658

5759
RegistryAtomicMutateRequest {
58-
mutations: vec![routing_table_mutation(&rt)],
60+
mutations: initial_routing_table_mutations(&rt),
5961
preconditions: vec![],
6062
}
6163
};

rs/registry/canister/tests/reroute_canister_ranges.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ic_nns_test_utils::{
44
local_test_on_nns_subnet, set_up_registry_canister, set_up_universal_canister,
55
try_call_via_universal_canister,
66
},
7-
registry::{prepare_registry_with_two_node_sets, routing_table_mutation},
7+
registry::{initial_routing_table_mutations, prepare_registry_with_two_node_sets},
88
};
99
use ic_registry_routing_table::{CanisterIdRange, RoutingTable};
1010
use ic_registry_transport::pb::v1::RegistryAtomicMutateRequest;
@@ -45,7 +45,7 @@ fn test_reroute_canister_ranges() {
4545
.expect("failed to update the routing table");
4646

4747
RegistryAtomicMutateRequest {
48-
mutations: vec![routing_table_mutation(&rt)],
48+
mutations: initial_routing_table_mutations(&rt),
4949
preconditions: vec![],
5050
}
5151
};

rs/registry/canister/tests/roll_back_canister_migration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use ic_nns_test_utils::{
44
local_test_on_nns_subnet, set_up_registry_canister, set_up_universal_canister,
55
try_call_via_universal_canister,
66
},
7-
registry::{prepare_registry_with_two_node_sets, routing_table_mutation},
7+
registry::{initial_routing_table_mutations, prepare_registry_with_two_node_sets},
88
};
99
use ic_registry_routing_table::{CanisterIdRange, RoutingTable};
1010
use ic_registry_transport::pb::v1::RegistryAtomicMutateRequest;
@@ -45,7 +45,7 @@ fn test_roll_back_canister_migration() {
4545
.expect("failed to update the routing table");
4646

4747
RegistryAtomicMutateRequest {
48-
mutations: vec![routing_table_mutation(&rt)],
48+
mutations: initial_routing_table_mutations(&rt),
4949
preconditions: vec![],
5050
}
5151
};

0 commit comments

Comments
 (0)