Skip to content

Commit 17f5d74

Browse files
author
Oleh Dokuka
committed
fixes flaky tests
Signed-off-by: Oleh Dokuka <[email protected]> Signed-off-by: Oleh Dokuka <[email protected]> Signed-off-by: OlegDokuka <[email protected]>
1 parent c65683e commit 17f5d74

File tree

3 files changed

+447
-409
lines changed

3 files changed

+447
-409
lines changed

rsocket-core/src/test/java/io/rsocket/core/AbstractSocketRule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public void init() {
4444
}
4545

4646
protected void doInit() {
47-
if (socket != null) {
48-
socket.dispose();
49-
}
5047
if (connection != null) {
5148
connection.dispose();
5249
}
50+
if (socket != null) {
51+
socket.dispose();
52+
}
5353
connection = new TestDuplexConnection(allocator);
5454
socket = newRSocket();
5555
}

rsocket-core/src/test/java/io/rsocket/loadbalance/WeightedLoadbalanceStrategyTest.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ public Mono<Void> fireAndForget(Payload payload) {
8080
LoadbalanceTarget.from("1", mockTransport),
8181
LoadbalanceTarget.from("2", mockTransport)));
8282

83-
Assertions.assertThat(counter1.get()).isCloseTo(1000, Offset.offset(1));
84-
Assertions.assertThat(counter2.get()).isCloseTo(0, Offset.offset(1));
83+
Assertions.assertThat(counter1.get())
84+
.describedAs("c1=" + counter1.get() + " c2=" + counter2.get())
85+
.isCloseTo(
86+
RaceTestConstants.REPEATS, Offset.offset(Math.round(RaceTestConstants.REPEATS * 0.1f)));
87+
Assertions.assertThat(counter2.get())
88+
.describedAs("c1=" + counter1.get() + " c2=" + counter2.get())
89+
.isCloseTo(0, Offset.offset(Math.round(RaceTestConstants.REPEATS * 0.1f)));
8590
}
8691

8792
@Test
@@ -165,8 +170,11 @@ public Mono<Void> fireAndForget(Payload payload) {
165170
}
166171

167172
Assertions.assertThat(counter1.get())
168-
.isCloseTo(RaceTestConstants.REPEATS * 3, Offset.offset(100));
169-
Assertions.assertThat(counter2.get()).isCloseTo(0, Offset.offset(100));
173+
.isCloseTo(
174+
RaceTestConstants.REPEATS * 3,
175+
Offset.offset(Math.round(RaceTestConstants.REPEATS * 3 * 0.1f)));
176+
Assertions.assertThat(counter2.get())
177+
.isCloseTo(0, Offset.offset(Math.round(RaceTestConstants.REPEATS * 3 * 0.1f)));
170178

171179
rSocket2.updateAvailability(0.0);
172180

@@ -177,8 +185,13 @@ public Mono<Void> fireAndForget(Payload payload) {
177185
}
178186

179187
Assertions.assertThat(counter1.get())
180-
.isCloseTo(RaceTestConstants.REPEATS * 3, Offset.offset(100));
181-
Assertions.assertThat(counter2.get()).isCloseTo(RaceTestConstants.REPEATS, Offset.offset(100));
188+
.isCloseTo(
189+
RaceTestConstants.REPEATS * 3,
190+
Offset.offset(Math.round(RaceTestConstants.REPEATS * 4 * 0.1f)));
191+
Assertions.assertThat(counter2.get())
192+
.isCloseTo(
193+
RaceTestConstants.REPEATS,
194+
Offset.offset(Math.round(RaceTestConstants.REPEATS * 4 * 0.1f)));
182195

183196
source.next(
184197
Arrays.asList(
@@ -191,9 +204,13 @@ public Mono<Void> fireAndForget(Payload payload) {
191204
}
192205

193206
Assertions.assertThat(counter1.get())
194-
.isCloseTo(RaceTestConstants.REPEATS * 3, Offset.offset(100));
207+
.isCloseTo(
208+
RaceTestConstants.REPEATS * 3,
209+
Offset.offset(Math.round(RaceTestConstants.REPEATS * 5 * 0.1f)));
195210
Assertions.assertThat(counter2.get())
196-
.isCloseTo(RaceTestConstants.REPEATS * 2, Offset.offset(100));
211+
.isCloseTo(
212+
RaceTestConstants.REPEATS * 2,
213+
Offset.offset(Math.round(RaceTestConstants.REPEATS * 5 * 0.1f)));
197214
}
198215

199216
static class WeightedTestRSocket extends BaseWeightedStats implements RSocket {

0 commit comments

Comments
 (0)