diff --git a/examples/test/qore/threads/max-threads-count.qtest b/examples/test/qore/threads/max-threads-count.qtest index d95d65e47c..7c2dad847e 100755 --- a/examples/test/qore/threads/max-threads-count.qtest +++ b/examples/test/qore/threads/max-threads-count.qtest @@ -24,7 +24,8 @@ public class MaxThreadCountTest inherits QUnit::Test { q = new Queue(); } - t() { + t(Counter c) { + on_exit c.dec(); q.get(); q.push(1); } @@ -34,16 +35,27 @@ public class MaxThreadCountTest inherits QUnit::Test { testSkip("skipping max thread test due to environment variable"); } + int limit = 0; + + Counter c(); try { while (True) { - background t(); + c.inc(); + on_error c.dec(); + background t(c); } } catch (hash ex) { assertEq("THREAD-CREATION-FAILURE", ex.err, "found threads count limit"); + limit = num_threads(); q.push(1); } - int nt = num_threads(); - assertTrue(nt > 1, "number of threads is " + nt); + if (m_options.verbose > 2) { + printf("max thread limit detected: %d\n", limit); + } + + assertGt(1, limit); + c.waitForZero(); + assertEq(1, num_threads()); } }