Are tests interruptible/concurrent? Is use of a (thread local) global safe in tests?

Mark Isaacson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 30 13:13:19 PDT 2014


I'm having fun running some unittests. I set up a simple homemade
mock of std.net.curl's functions that essentially just consists
of a global queue that I can add strings to and get back in a
predictable order when calling std.net.curl.get/post/etc.

I use this mock in a couple of different modules for unit
testing, namely the module I have the mock in and one other one.
When I run my unit tests, it seems to enqueue all of the
responses from both of my unit tests (from different modules)
before finishing those tests and removing things from the global
queue. This is problematic in that I cannot anticipate the state
of the global queue for my tests. Does this sound more like a bug
or a "feature". My understanding is that, at least for now, tests
are not run concurrently on the latest official dmd release;
since my queue is not qualified with shared, things should be
thread local anyway.

TLDR:
Executation of tests A and B is as follows:
A pushes to global queue
B pushes to global queue
B pops on global queue -- program crashes

Expected order:
A pushes to global queue
A pops from global queue
B pushes to global queue
B pops from global queue

Or switch the order in which A and B execute, doesn't really
matter.



More information about the Digitalmars-d-learn mailing list