Unittests being broken

René Zwanenburg renezwanenburg at gmail.com
Thu May 5 10:01:18 UTC 2022


On Thursday, 5 May 2022 at 01:44:37 UTC, Ruby The Roobster wrote:
> Some code I have:
> (...)
> What can I do to fix this?

I didn't try your code, but opList, funcList, and noTouch are 
thread-local variables, and you fill them in a shared static 
this. This means they will remain empty in any thread other than 
the main one. The test would fail in the way you describe if they 
are empty. So, I bet the tests run in another thread.

Of this is indeed the problem you can either:
- Make the lists immutable. This implicitly shares them among 
threads. But it looks like you want to modify them so immutable 
won't work in this case.

- If you don't want / need to share the lists over threads, fill 
them using a normal static this instead.

- If you do need to share them over threads, mark the lists as 
shared /
__gshared, but you'll be responsible for accessing them in a 
thread-safe manner.


More information about the Digitalmars-d-learn mailing list