Skip to content

Commit 03cacde

Browse files
committed
* Attempt to increase the probability of observing the issue described in AXIS-2498 in MultithreadTestCase.
* Ensure that MultithreadTestCase will report hanging threads (instead of blocking the build).
1 parent 68b24f7 commit 03cacde

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

integration/src/test/java/test/wsdl/multithread/Invoker.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package test.wsdl.multithread;
2020

21+
import java.util.concurrent.CountDownLatch;
22+
2123
import org.apache.axis.components.logger.LogFactory;
2224
import org.apache.commons.logging.Log;
2325

@@ -30,15 +32,24 @@ class Invoker implements Runnable {
3032
private static Log log = LogFactory.getLog(Invoker.class.getName());
3133

3234
private final AddressBook binding;
35+
private final CountDownLatch readyLatch;
36+
private final CountDownLatch startLatch;
3337
private final Report report;
3438

35-
Invoker(AddressBook binding, Report report) {
39+
Invoker(AddressBook binding, CountDownLatch readyLatch, CountDownLatch startLatch, Report report) {
3640
this.binding = binding;
41+
this.readyLatch = readyLatch;
42+
this.startLatch = startLatch;
3743
this.report = report;
3844
}
3945

4046
public void run() {
4147
try {
48+
// This ensures that all threads start sending requests at the same time,
49+
// thereby increasing the probability of triggering a concurrency issue.
50+
readyLatch.countDown();
51+
startLatch.await();
52+
4253
for (int i = 0; i < 4; ++i) {
4354
Address address = new Address();
4455
Phone phone = new Phone();

integration/src/test/java/test/wsdl/multithread/MultithreadTestCase.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package test.wsdl.multithread;
22

3+
import java.util.concurrent.CountDownLatch;
4+
35
import junit.framework.TestCase;
46
import samples.addr.AddressBook;
57
import samples.addr.AddressBookSOAPBindingStub;
@@ -44,16 +46,22 @@ public AddressBook getStub() throws Exception {
4446
private void testMultithreading(StubSupplier stubSupplier) throws Throwable {
4547
Report report = new Report();
4648
int NUM_THREADS = 50;
49+
CountDownLatch readyLatch = new CountDownLatch(NUM_THREADS);
50+
CountDownLatch startLatch = new CountDownLatch(1);
4751
Thread[] threads = new Thread[NUM_THREADS];
4852
for (int i = 0; i < NUM_THREADS; ++i) {
49-
threads[i] = new Thread(new Invoker(stubSupplier.getStub(), report));
53+
threads[i] = new Thread(new Invoker(stubSupplier.getStub(), readyLatch, startLatch, report));
5054
threads[i].start();
5155
}
56+
readyLatch.await();
57+
startLatch.countDown();
5258
for (int i = 0; i < NUM_THREADS; ++i) {
53-
try {
54-
threads[i].join();
55-
}
56-
catch (InterruptedException ie) {
59+
threads[i].join(30000);
60+
StackTraceElement[] stack = threads[i].getStackTrace();
61+
if (stack.length > 0) {
62+
Throwable t = new Throwable("Hanging thread detected");
63+
t.setStackTrace(stack);
64+
throw t;
5765
}
5866
}
5967
Throwable error = report.getError();

0 commit comments

Comments
 (0)