Skip to content

Commit c39e7db

Browse files
committed
filters: try to address some of the flaky tests on windows
1 parent 645c52a commit c39e7db

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

filters/statistics/src/main/java/de/learnlib/filter/statistic/container/MapStatisticsService.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public void clear() {
8383
public String print() {
8484

8585
final StringBuilder sb = new StringBuilder(125);
86-
sb.append("Statistics:")
87-
.append(System.lineSeparator())
88-
.append("============================================")
89-
.append(System.lineSeparator());
86+
sb.append("""
87+
Statistics:
88+
============================================
89+
""");
9090

9191
final ReadLock lock = this.lock.readLock();
9292
lock.lock();
@@ -103,20 +103,16 @@ public String print() {
103103
sb.append(": ").append(map.values().iterator().next());
104104
} else {
105105
for (Entry<Integer, StatisticContainer> e2 : map.entrySet()) {
106-
sb.append(System.lineSeparator())
107-
.append(" * Instance ")
108-
.append(e2.getKey())
109-
.append(": ")
110-
.append(e2.getValue());
106+
sb.append("\n * Instance ").append(e2.getKey()).append(": ").append(e2.getValue());
111107
}
112108
}
113-
sb.append(System.lineSeparator());
109+
sb.append('\n');
114110
}
115111
} finally {
116112
lock.unlock();
117113
}
118114

119-
sb.append("============================================").append(System.lineSeparator());
115+
sb.append("============================================\n");
120116

121117
return sb.toString();
122118
}
@@ -343,7 +339,8 @@ private <T> Optional<T> getData(StatisticsKey key,
343339
LOGGER.debug("Key '{}' has been written by objects '{}', aggregating ...", key, stats.keySet());
344340
}
345341

346-
@NonNull T result = initialValue;
342+
@NonNull
343+
T result = initialValue;
347344
boolean written = false;
348345

349346
for (StatisticContainer container : stats.values()) {

filters/statistics/src/test/java/de/learnlib/filter/statistic/MapStatisticsServiceTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ public void testAggregationClock() {
152152
final Duration c11 = tester.getClock(key1, owner1).orElseThrow();
153153
final Duration c12 = tester.getClock(key1, owner2).orElseThrow();
154154

155-
Assert.assertTrue(c11.getNano() > 0);
156-
Assert.assertTrue(c12.getNano() > 0);
155+
Assert.assertTrue(c11.compareTo(Duration.ZERO) > 0);
156+
Assert.assertTrue(c12.compareTo(Duration.ZERO) > 0);
157157
Assert.assertEquals(tester.getClock(key1).orElseThrow(), c11.plus(c12));
158158

159159
final Duration c21 = tester.getClock(key2, owner1).orElseThrow();
160160
final Duration c32 = tester.getClock(key3, owner2).orElseThrow();
161161

162-
Assert.assertTrue(c21.getNano() > 0);
163-
Assert.assertTrue(c32.getNano() > 0);
162+
Assert.assertTrue(c21.compareTo(Duration.ZERO) > 0);
163+
Assert.assertTrue(c32.compareTo(Duration.ZERO) > 0);
164164
Assert.assertEquals(tester.getClock(key2, owner1).orElseThrow(), c21);
165165
Assert.assertEquals(tester.getClock(key3, owner2).orElseThrow(), c32);
166166

167-
Assert.assertEquals(new HashSet<>(tester.getClocks(key1).values()), Set.of(c11, c12));
167+
Assert.assertEquals(new HashSet<>(tester.getClocks(key1).values()), new HashSet<>(Arrays.asList(c11, c12)));
168168
Assert.assertEquals(tester.getClocks(key2).values(), Collections.singleton(c21));
169169
Assert.assertEquals(tester.getClocks(key3).values(), Collections.singleton(c32));
170170

@@ -265,15 +265,15 @@ public void testInsertRetrievalClock() {
265265
Assert.assertEquals(statistics.getClock(KEY_CLOCK).orElseThrow(), Duration.ZERO);
266266

267267
statistics.pauseClock(KEY_CLOCK);
268-
final long nanos1 = statistics.getClock(KEY_CLOCK).orElseThrow().toNanos();
269-
Assert.assertTrue(nanos1 > 0L);
268+
Duration c1 = statistics.getClock(KEY_CLOCK).orElseThrow();
269+
Assert.assertTrue(c1.compareTo(Duration.ZERO) > 0);
270270

271271
statistics.startOrResumeClock(KEY_CLOCK);
272272
Assert.assertTrue(statistics.getClock(KEY_CLOCK).isPresent());
273273

274274
statistics.pauseClock(KEY_CLOCK);
275-
final long nanos2 = statistics.getClock(KEY_CLOCK).orElseThrow().toNanos();
276-
Assert.assertTrue(nanos2 > nanos1);
275+
Duration c2 = statistics.getClock(KEY_CLOCK).orElseThrow();
276+
Assert.assertTrue(c2.compareTo(c1) > 0);
277277

278278
Assert.assertTrue(statistics.getText(KEY_TEXT).isEmpty());
279279
Assert.assertTrue(statistics.getFlag(KEY_FLAG).isEmpty());
@@ -444,6 +444,7 @@ public void testDisplay() {
444444
============================================
445445
""");
446446

447-
Assert.assertTrue(pattern.matcher(statistics.print()).matches());
447+
String output = statistics.print();
448+
Assert.assertTrue(pattern.matcher(output).matches(), output);
448449
}
449450
}

0 commit comments

Comments
 (0)