Skip to content

Commit

Permalink
Reduce test flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
larry-safran committed Jul 28, 2023
1 parent c5c37ac commit 0691fda
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ weightedSubchannel2.new OrcaReportListener(weightedConfig.errorUtilizationPenalt
}
assertThat(pickCount.size()).isEqualTo(2);
// within blackout period, fallback to simple round robin
assertThat(Math.abs(pickCount.get(weightedSubchannel1) / 1000.0 - 0.5)).isAtMost(0.001);
assertThat(Math.abs(pickCount.get(weightedSubchannel2) / 1000.0 - 0.5)).isAtMost(0.001);
assertThat(Math.abs(pickCount.get(weightedSubchannel1) / 1000.0 - 0.5)).isLessThan(0.002);
assertThat(Math.abs(pickCount.get(weightedSubchannel2) / 1000.0 - 0.5)).isLessThan(0.002);

assertThat(fakeClock.forwardTime(5, TimeUnit.SECONDS)).isEqualTo(1);
pickCount = new HashMap<>();
Expand All @@ -532,9 +532,9 @@ weightedSubchannel2.new OrcaReportListener(weightedConfig.errorUtilizationPenalt
assertThat(pickCount.size()).isEqualTo(2);
// after blackout period
assertThat(Math.abs(pickCount.get(weightedSubchannel1) / 1000.0 - 2.0 / 3))
.isAtMost(0.001);
.isLessThan(0.002);
assertThat(Math.abs(pickCount.get(weightedSubchannel2) / 1000.0 - 1.0 / 3))
.isAtMost(0.001);
.isLessThan(0.002);
}

@Test
Expand Down Expand Up @@ -632,9 +632,9 @@ weightedSubchannel2.new OrcaReportListener(weightedConfig.errorUtilizationPenalt
}
assertThat(pickCount.size()).isEqualTo(2);
assertThat(Math.abs(pickCount.get(weightedSubchannel1) / 1000.0 - 2.0 / 3))
.isAtMost(0.001);
.isLessThan(0.002);
assertThat(Math.abs(pickCount.get(weightedSubchannel2) / 1000.0 - 1.0 / 3))
.isAtMost(0.001);
.isLessThan(0.002);

// weight expired, fallback to simple round robin
assertThat(fakeClock.forwardTime(300, TimeUnit.SECONDS)).isEqualTo(1);
Expand All @@ -645,9 +645,9 @@ weightedSubchannel2.new OrcaReportListener(weightedConfig.errorUtilizationPenalt
}
assertThat(pickCount.size()).isEqualTo(2);
assertThat(Math.abs(pickCount.get(weightedSubchannel1) / 1000.0 - 0.5))
.isAtMost(0.001);
.isLessThan(0.002);
assertThat(Math.abs(pickCount.get(weightedSubchannel2) / 1000.0 - 0.5))
.isAtMost(0.001);
.isLessThan(0.002);
}

@Test
Expand Down Expand Up @@ -751,12 +751,12 @@ weightedSubchannel2.new OrcaReportListener(weightedConfig.errorUtilizationPenalt
}
assertThat(pickCount.size()).isEqualTo(3);
assertThat(Math.abs(pickCount.get(weightedSubchannel1) / 1000.0 - 4.0 / 9))
.isAtMost(0.001);
.isLessThan(0.002);
assertThat(Math.abs(pickCount.get(weightedSubchannel2) / 1000.0 - 2.0 / 9))
.isAtMost(0.001);
.isLessThan(0.002);
// subchannel3's weight is average of subchannel1 and subchannel2
assertThat(Math.abs(pickCount.get(weightedSubchannel3) / 1000.0 - 3.0 / 9))
.isAtMost(0.001);
.isLessThan(0.002);
}

@Test
Expand Down Expand Up @@ -817,9 +817,9 @@ public void run() {
assertThat(pickCount.size()).isEqualTo(2);
// after blackout period
assertThat(Math.abs(pickCount.get(weightedSubchannel1).get() / 2000.0 - 2.0 / 3))
.isAtMost(0.001);
.isLessThan(0.002);
assertThat(Math.abs(pickCount.get(weightedSubchannel2).get() / 2000.0 - 1.0 / 3))
.isAtMost(0.001);
.isLessThan(0.002);
}

@Test(expected = NullPointerException.class)
Expand Down Expand Up @@ -947,7 +947,7 @@ public void testStaticStrideSchedulerNonIntegers1() {
}
for (int i = 0; i < 3; i++) {
assertThat(Math.abs(pickCount.getOrDefault(i, 0) / 1000.0 - weights[i] / totalWeight))
.isAtMost(0.001);
.isLessThan(0.002);
}
}

Expand All @@ -964,7 +964,7 @@ public void testStaticStrideSchedulerNonIntegers2() {
}
for (int i = 0; i < 3; i++) {
assertThat(Math.abs(pickCount.getOrDefault(i, 0) / 1000.0 - weights[i] / totalWeight))
.isAtMost(0.001);
.isLessThan(0.002);
}
}

Expand All @@ -981,7 +981,7 @@ public void testTwoWeights() {
}
for (int i = 0; i < 2; i++) {
assertThat(Math.abs(pickCount.getOrDefault(i, 0) / 1000.0 - weights[i] / totalWeight))
.isAtMost(0.001);
.isLessThan(0.002);
}
}

Expand All @@ -998,7 +998,7 @@ public void testManyWeights() {
}
for (int i = 0; i < 5; i++) {
assertThat(Math.abs(pickCount.getOrDefault(i, 0) / 1000.0 - weights[i] / totalWeight))
.isAtMost(0.0011);
.isLessThan(0.0021);
}
}

Expand Down Expand Up @@ -1052,7 +1052,7 @@ public void testImmediateWraparound() {
}
for (int i = 0; i < 5; i++) {
assertThat(Math.abs(pickCount.getOrDefault(i, 0) / 1000.0 - weights[i] / totalWeight))
.isAtMost(0.001);
.isLessThan(0.002);
}
}

Expand All @@ -1069,7 +1069,7 @@ public void testWraparound() {
}
for (int i = 0; i < 5; i++) {
assertThat(Math.abs(pickCount.getOrDefault(i, 0) / 1000.0 - weights[i] / totalWeight))
.isAtMost(0.0011);
.isLessThan(0.0021);
}
}

Expand Down

0 comments on commit 0691fda

Please sign in to comment.