Skip to content

Commit c271d7f

Browse files
appium#283 fix: The locking is fair now.
+ Multithreading test improvement.
1 parent f002719 commit c271d7f

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/main/java/io/appium/java_client/service/local/AppiumDriverLocalService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class AppiumDriverLocalService extends DriverService {
4444
private final String ipAddress;
4545
private final long startupTimeout;
4646
private final TimeUnit timeUnit;
47-
private final ReentrantLock lock = new ReentrantLock();
47+
private final ReentrantLock lock = new ReentrantLock(true);
4848
private final ListOutputStream stream = new ListOutputStream().add(System.out);
4949

5050

src/test/java/io/appium/java_client/localserver/ThreadSafetyTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ public void whenFewTreadsDoDifferentWork() throws Throwable {
204204
assertTrue(stopTestThread.result.equals("OK")); //and then the test tried to shut down it (see (3))
205205
assertTrue(!service.isRunning());
206206

207-
stopThread2.start(); // (1)
208-
isRunningThread2.start(); // (2)
207+
isRunningThread2.start(); // (1)
208+
Thread.sleep(10);
209+
stopThread2.start(); // (2)
210+
Thread.sleep(10);
209211
runThread2.start(); //(3)
210212

211213
while (runThread2.isAlive() || isRunningThread2.isAlive() || stopThread2.isAlive()) {
@@ -224,8 +226,8 @@ public void whenFewTreadsDoDifferentWork() throws Throwable {
224226
throw stopTestThread.t;
225227
}
226228

227-
assertTrue(stopTestThread2.result.equals("OK")); //the service had not been started firstly (see (1)), it is ok
228-
assertTrue(isRunningTestThread2.result.equals(false)); //so it couldn't being running (see (2))
229+
assertTrue(isRunningTestThread2.result.equals(false)); //the service wasn't being running (see (1))
230+
assertTrue(stopTestThread2.result.equals("OK")); //the service had not been started firstly (see (2)), it is ok
229231
assertTrue(runTestThread2.result.equals("OK")); //and then it was started (see (3))
230232
assertTrue(service.isRunning());
231233
}

0 commit comments

Comments
 (0)