testfx
testfx copied to clipboard
Accessing a unique worker ID during runtime
I require the ability to access the current workers ID at runtime. Something like the Thread.CurrentThread.ManagedThreadID feature. I want the ability to say Worker.GetWorkerID or something like that. Does anyone know if there is a feature like this?
There isn't any such feature right now.
Why wouldn't Thread.CurrentThread.ManagedThreadID itself work for you? And i'm guessing you need this when in-assembly parallelism is enabled?
Thats a shame :( and Yes I have tried this method, but the thread ID changes randomly mid run. See https://stackoverflow.com/questions/57414909/managedthreadid-changing-at-runtime
I have tried using the thread ID. Maybe i am doing something wrong.
ive narrowed down the threadID issue. If I am creating a thread under the classInitialize but trying to destroy the thread under class cleanup. they work off different threads... wtf?
[2019-08-09 08:21:56] AssemblyInitialize: 12 [2019-08-09 08:21:56] ClassInitialize: 12 [2019-08-09 08:21:56] TestMethod: 12 [2019-08-09 08:21:56] ClassCleanUp: 4 [2019-08-09 08:21:56] AssemblyCleanup: 4
Just simply logging those threads during run time... why would they be changing. Any idea why this is happening?
<!-- MSTest adapter -->
<MSTest>
<Parallelize>
<Workers>1</Workers>
<Scope>ClassLevel</Scope>
</Parallelize>
</MSTest>
@KitoCoding yeah so class cleanup and assembly cleanup are sorta invoked at the very end. There is a related issue where someone was asking that these be done immediately after running all tests of a class/assembly.
Since we run these at the end i'm guessing different threads run the cleanup methods.
Class cleanup and assembly cleanup are common for a bunch of tests so it is quite likely that even if they are called immediately after all tests of a class/assembly finish it will likely be picked up by a random thread.
Yeah it was probably me that try to start that thread lol. Ms test is prioritized for some reason to run one worker per test method. However you add the ability to have one worker pertest class. but the functionality around it as in this case where I need the test cleanup methods to run on the same thread, break. or when a test clean up method is being called at the very end when I need it to run at the end of a workers lifetime.
@KitoCoding fair ask, but we will be prioritizing this based on popularity of the feature request.