Skip to content

Commit ff6bdec

Browse files
committed
revert: ubuntu 24.04 failing to terminate schedulers during test
1 parent 09d91a2 commit ff6bdec

8 files changed

Lines changed: 21 additions & 60 deletions

File tree

.github/workflows/master-2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build-scan:
1111
name: SonarCloud Scan
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313

1414
steps:
1515
- uses: actions/checkout@v4
@@ -35,7 +35,7 @@ jobs:
3535
fail-fast: false
3636
matrix:
3737
java: ['11', '17', '21']
38-
os: [ubuntu-latest, windows-latest]
38+
os: [ubuntu-22.04, windows-latest]
3939
runs-on: ${{ matrix.os }}
4040

4141
steps:

.github/workflows/master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build-scan:
1111
name: SonarCloud Scan
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313

1414
steps:
1515
- uses: actions/checkout@v4
@@ -35,7 +35,7 @@ jobs:
3535
fail-fast: false
3636
matrix:
3737
java: ['8', '11', '17', '21']
38-
os: [ubuntu-latest, windows-latest]
38+
os: [ubuntu-22.04, windows-latest]
3939
runs-on: ${{ matrix.os }}
4040

4141
steps:

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
java: ['11', '17', '21']
14-
os: [ubuntu-latest, windows-latest]
14+
os: [ubuntu-22.04, windows-latest]
1515
runs-on: ${{ matrix.os }}
1616

1717
steps:
@@ -39,7 +39,7 @@ jobs:
3939
publish:
4040
name: Publish Release
4141
needs: [build-test]
42-
runs-on: ubuntu-latest
42+
runs-on: ubuntu-22.04
4343

4444
steps:
4545
- uses: actions/checkout@v4

.github/workflows/sonar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
jobs:
1212
sonar-analysis:
1313
name: SonarCloud Analysis for PR
14-
runs-on: ubuntu-latest
14+
runs-on: ubuntu-22.04
1515

1616
steps:
1717
- name: Get PR details

src/main/java/com/switcherapi/client/SwitcherContextBase.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,9 @@ public static void watchSnapshot(SnapshotEventHandler handler) {
461461
*/
462462
public static void stopWatchingSnapshot() {
463463
if (Objects.nonNull(watcherSnapshot)) {
464-
watcherExecutorService.shutdown();
465-
try {
466-
if (!watcherExecutorService.awaitTermination(5, TimeUnit.SECONDS)) {
467-
watcherExecutorService.shutdownNow();
468-
}
469-
} catch (InterruptedException e) {
470-
watcherExecutorService.shutdownNow();
471-
Thread.currentThread().interrupt();
472-
} finally {
473-
watcherSnapshot.terminate();
474-
watcherSnapshot = null;
475-
}
464+
watcherExecutorService.shutdownNow();
465+
watcherSnapshot.terminate();
466+
watcherSnapshot = null;
476467
}
477468
}
478469

src/test/java/com/switcherapi/client/utils/SnapshotTest.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.switcherapi.client.service.WorkerName;
88
import com.google.gson.Gson;
99
import com.google.gson.GsonBuilder;
10-
import com.switcherapi.fixture.CountDownHelper;
1110
import org.apache.commons.lang3.StringUtils;
1211
import org.slf4j.Logger;
1312
import org.slf4j.LoggerFactory;
@@ -75,20 +74,4 @@ protected void assertWorker(boolean exists) {
7574
assertEquals(exists, Thread.getAllStackTraces().keySet().stream()
7675
.anyMatch(t -> t.getName().equals(WorkerName.SNAPSHOT_WATCH_WORKER.toString())));
7776
}
78-
79-
protected void assertWorkerUntil(boolean exists, long seconds) {
80-
long count = 0;
81-
while (count < seconds) {
82-
if (Thread.getAllStackTraces().keySet().stream()
83-
.anyMatch(t -> t.getName().equals(WorkerName.SNAPSHOT_WATCH_WORKER.toString())) == exists) {
84-
break;
85-
}
86-
87-
CountDownHelper.wait(1);
88-
count++;
89-
}
90-
91-
assertEquals(exists, Thread.getAllStackTraces().keySet().stream()
92-
.anyMatch(t -> t.getName().equals(WorkerName.SNAPSHOT_WATCH_WORKER.toString())));
93-
}
9477
}

src/test/java/com/switcherapi/client/utils/SnapshotWatcherTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import com.switcherapi.client.ContextBuilder;
55
import com.switcherapi.client.model.SwitcherRequest;
66
import com.switcherapi.fixture.CountDownHelper;
7-
import org.junit.jupiter.api.*;
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.BeforeAll;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
811

912
import java.io.IOException;
1013

@@ -26,17 +29,17 @@ static void setupContext() throws IOException {
2629

2730
SwitchersBase.initializeClient();
2831
}
32+
33+
@AfterAll
34+
static void tearDown() {
35+
SwitchersBase.stopWatchingSnapshot();
36+
}
2937

3038
@BeforeEach
3139
void prepareTest() {
3240
generateFixture();
3341
SwitchersBase.watchSnapshot();
3442
}
35-
36-
@AfterEach
37-
void cleanUp() {
38-
SwitchersBase.stopWatchingSnapshot();
39-
}
4043

4144
@Test
4245
void shouldNotReloadDomainAfterChangingSnapshot() {

src/test/java/com/switcherapi/client/utils/SnapshotWatcherWorkerTest.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.switcherapi.SwitchersBase;
44
import com.switcherapi.client.ContextBuilder;
5-
import com.switcherapi.client.service.WorkerName;
65
import com.switcherapi.fixture.CountDownHelper;
76
import org.junit.jupiter.api.BeforeAll;
87
import org.junit.jupiter.api.Test;
@@ -23,27 +22,12 @@ static void setupContext() {
2322
@Test
2423
void shouldStartAndKillWorker() {
2524
SwitchersBase.watchSnapshot();
26-
CountDownHelper.wait(1);
27-
assertWorkerUntil(true, 2);
28-
29-
Thread.getAllStackTraces().keySet()
30-
.forEach(t -> {
31-
if (t.getName().equals(WorkerName.SNAPSHOT_WATCH_WORKER.toString())) {
32-
System.out.println("Thread: " + t.getName() + " - Alive: " + t.isAlive());
33-
}
34-
});
25+
assertWorker(true);
3526

3627
SwitchersBase.stopWatchingSnapshot();
3728
CountDownHelper.wait(2);
3829

39-
Thread.getAllStackTraces().keySet()
40-
.forEach(t -> {
41-
if (t.getName().equals(WorkerName.SNAPSHOT_WATCH_WORKER.toString())) {
42-
System.out.println("Thread: " + t.getName() + " - Alive: " + t.isAlive());
43-
}
44-
});
45-
46-
assertWorkerUntil(false, 10);
30+
assertWorker(false);
4731
}
4832

4933
}

0 commit comments

Comments
 (0)