Implementation Synchronous and Asynchronous Test in TDD

After learning about implementation of integration test, my next task will be testing out concurrency situation, where ID increment behaviour upon user deleting existing data and adding new data at the same time. Test is done by implementing two different task function. The flows of tasks is controlled by using semaphore implementation which is WaitAsync() and Release().

Initially, I implement the asynchronous test by separating add data and delete data into two task. Then I create new semaphore instances of semaLock1 and semaLock2. Hence, I control the tasks using semaphore, start the test by implementing task as user’s control. task Delete start, Meanwhile, task Add will begin and end first before task Delete end. The test was partially successful as I successfully increment the ID. However, I am unable to perform the asynchronous test as the delete function throws out multiple exception, despite I implement try catch blocks.

After a long time of struggle, I seek help from supervisor and we decide to make it simple, and perform the test synchronously. The test is much more simpler, but it is sufficient to proof the behaviour of function as planned.

I also did test of deleting existing data and adding new add after in asynchronous way. Which it only requires me to use same function from last test, to decrement current ID when latest data is deleted, and increment current ID when new data added.

Lastly, what I am able to observe during these tests, is that semaphore provides a good control to manage the flow of codes, but it might put user into infinite loops whenever semaphore is implement wrongly. For example, when there is only two semaLock in my test, semaLock1.WaitAsync() and semaLock2.WaitAsync() would make both task waits for each other.