Currently, I am tackling a TS project that involves testing concurrent code and its interactions with a database, specifically focusing on idepotency. My goal is to ensure that multiple requests modifying the same resource will either apply changes correctly or fail, without experiencing lost updates or double processing.
While I have extensive experience testing similar scenarios in Java due to its abundance of concurrency primitives like semaphores and barriers, I am struggling to translate this knowledge into TypeScript.
In Java, for instance, I would initiate 2 threads using a CyclicBarrier with 2 parties. These threads would reach the barrier, wait for each other, then continue execution, allowing me to validate the code's functionality effectively. If parallel execution could not be guaranteed, I would repeat the test multiple times or use more threads to increase chances of parallelism.
Unfortunately, I have not come across any similar concurrency primitives in JS to replicate this process. The closest workaround I found was busy waiting on a shared value or utilizing worker threads as suggested by some blogs.
If anyone has suggestions on how to approach this challenge in TypeScript, I would greatly appreciate it! This topic poses several difficulties, so links to relevant blogs, articles, and books are welcome!