I have created a large number of automated tests for my app. There’s one set of tests that I can’t seem to get going right, and I’m looking for some advice… Am I being too ambitious here?
The underlying requirement of all the tests is to have multiple endpoints creating changes that are delivered to other endpoints and to confirm that all Endpoints maintain consistency.
In the tests, I create several EndPoint objects, each containing a Database object (with its own unique db file), a Live Query, and a replication, all created in its own thread. Each endpoint then starts making and saving change documents, which get synced. Each endpoint is also receiving the change documents from the other EndPoints, which are then integrated into their data. The test is to make sure everything stays sane.
I have a variety of ways to create change sets from the EndPoints, each of which represents different tests. Some examples:
- slowly create changes from each EndPoint in turn
- rapidly create changes from all EndPoints in parallel,
- create conflicting changes,
- one or more endpoints go offline for a while, then come back and catch up.
… and so on. Many many such tests.
Mostly things work.
The weird thing is that at the end of some of the tests, I need to wait for syncing to settle before testing that all the endpoints are in a sane state. So in my UnitTest code - I have something like this at the end:
Thread.Sleep(20000); /// wait for some time to ensure the final sync has started
while (the state of any replicator is busy)
Thread.Sleep(500);
Assert.That( all endpoints have sane state )
Yeah… its ugly. But performance is not important in this test, accuracy is. I need to wait for all replication to have finished before checking for a sane state.
The problem is that once I enter this wait, no further syncing will happen. No matter how long I wait at the “wait for some time…” line, I dont receive the final change events.
It seems to me that the operation of the Replication or LiveQuery is, in some way, blocking on the main thread, even though the Endpoints are all created in separate threads. Looking in the forums, there has been an interesting conversations about the LiveQueries, Main Threads and Java (here). In that conversation, borrrden made the comment:
I work in the .NET version and we don’t have any concept of a main thread in a cross platform sense so by default it uses a thread pool background thread for the same operation here
so I wouldn’t expect LiveQueries to suffer from these problems. However I am running in NUnit, so perhaps something different is going on.
What am I missing? Is it too ambitious to run multiple Databases, Live Queries and Replicators in the same Unit Test app?
Many thanks for any advice you can provide.
Paul.