- A Concurrent Affair - https://www.concurrentaffair.org -

Possible ConcJUnit Enhancement

I’m writing a paper about ConcJUnit [1], this time with an educational focus, and as usual, writing helps me in systematically covering the problem space. I shouldn’t spend a whole lot of time blogging now, because the paper submission deadline is approaching fast, but I want to make a more-than-just-mental note anyway.

ConcJUnit can emit “lucky” warnings if all child threads terminated before a test ended, but this was not enforced with a join. Daemon threads are exempt from this requirement, because they should shut down by themselves in a real program.

Now, what happens if I refactor my program and change something like this

1
2
3
4
5
6
7
8
9
10
public void someOperation() {
    // ...
    fail();
}

public void testFoo() {
    new Thread [2]() {
        public void run() { someOperation(); }
    }.start();
}

which will correctly warn me that the new thread wasn’t joined, into something like this:

1
2
3
4
5
public void testFoo() {
    EventQueue [3].invokeLater(new Runnable [4]() {
        public void run() { someOperation(); }
    });
}

This code puts the task on the event queue, but because the event thread is a daemon thread, ConcJUnit does not warn that the operation may not have had time to fail yet.

Perhaps I can enqueue a “token” event at the end of a test and wait for it to be processed?

[5] [6]Share [7]