Skip to content

threepointone/durable-ordering

Repository files navigation

Testing Durable Ordering


(To run the test against the deployed worker, run npm run test.)

This is a test to see whether blockConcurrencyWhile actually blocks concurrency.

The worker has a Durable Object, inside which, inside a blockConcurrencyWhile call, it sleps for a random period of time between 0 and 400ms and then increments a counter. It persists the counter, then returns it.

const count = await this.ctx.blockConcurrencyWhile(async () => {
  await sleep(Math.random() * 400);
  const count = (await this.ctx.storage.get<number | null>("count")) || 0;
  await this.ctx.storage.put("count", count + 1);
  return count + 1;
});
return new Response(count.toString());

The test makes 40 requests to the worker, with a 50ms delay between each request. It then checks whether the counter is incremented correctly.

If blockConcurrencyWhile actually blocks request concurrency, then the counter should be incremented correctly. However, we see that it doesn't. Inside the Durable Object itself, we seem to be processing requests in order, but the reponses don't come in order. What is the expected behaviour?

Example trial run:

Running test, this may take a few seconds...
Final counter array: [
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 18, 17, 16, 15, 14, 20, 22, 19, 24,
  23, 28, 30, 26, 33, 21, 31, 25, 35, 27, 38, 39, 32, 40, 29, 37, 34, 36
]
Mismatches found: 24 at indices: [
  13, 14, 16, 17, 18, 19, 20, 21, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
  36, 37, 38, 39
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published