for @NathanosDev and @mraszyk: I was writing a test who’s purpose was to call the same function 3 times in the same block and make sure that only one executes. Something like:
const executePromises = [
env.myCanister.actor.withdraw(),
env.myCanister.actor.withdraw(),
env.myCanister.actor.withdraw(),
];
pic.tick(5);
const results = await Promise.all(executePromises);
pic.advanceTime((5 * 60 *1000));
pic.tick(10);
expect(results).toEqual([{ok : 0},[{err: lock}], [{err:lock};
The withdraw
function calls a number of things including making a cross-subnet call from an application subnet to the ICP canister on the system subnet to check a balance. I would expect that when I hit this await in my code that any fulfilment of that would pushed from Round 0 to Round 1 and that the other calls would be scheduled during Round 0.
But what is happening is that all cross-subnet calls from the first call are being fulfilled before the second call ever gets a chance to run. Thus I get an ok on all my calls because the lock I put there is released.
I’m trying to figure out if this is expected behavior or not. If it is unexpected, is it a function of how pic.js does async calls?
Maybe the js await is forcing a set of tick calls until it gets to the end of the await call? If that is the case, is there a way to do this test with Pic.js? Or even with pocket ic?
My understanding is that if these items were on the same subnet then they could execute immediately in the same block, but I’d think that an incoming ingress would get scheduled before any follow up awaits. Maybe PocketIC doesn’t use the same scheduling system as the replica?
I’ve tried to make sure that my topology is correct and that I have 2 application subnets plus the NNS to make sure these calls are crossing boundaries and it seems to be configured correctly.
getTopology [
{
id: Principal { _arr: [Uint8Array], _isPrincipal: true },
type: 'NNS',
size: undefined,
canisterRanges: [ [Object] ]
},
{
id: Principal { _arr: [Uint8Array], _isPrincipal: true },
type: 'Application',
size: undefined,
canisterRanges: [ [Object] ]
},
{
id: Principal { _arr: [Uint8Array], _isPrincipal: true },
type: 'Application',
size: undefined,
canisterRanges: [ [Object] ]
}
]
I’m using pic.js latest beta.