Skip to content

Commit

Permalink
Don't rely on test code execution time span for RemoteSegmentTransfer…
Browse files Browse the repository at this point in the history
…TrackerTests (#15187) (#15244)

(cherry picked from commit ef1a79f)

Signed-off-by: Lukáš Vlček <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent e66bcdf commit f225b4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class RemoteSegmentTransferTracker extends RemoteTransferTracker {
private volatile long remoteRefreshSeqNo;

/**
* The refresh time of most recent remote refresh.
* The refresh time of the most recent remote refresh.
*/
private volatile long remoteRefreshTimeMs;

Expand All @@ -76,7 +76,7 @@ public class RemoteSegmentTransferTracker extends RemoteTransferTracker {
private volatile long remoteRefreshStartTimeMs = -1;

/**
* The refresh time(clock) of most recent remote refresh.
* The refresh time(clock) of the most recent remote refresh.
*/
private volatile long remoteRefreshClockTimeMs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,18 @@ public void testComputeTimeLagOnUpdate() throws InterruptedException {
transferTracker.updateLocalRefreshTimeMs(currentTimeMsUsingSystemNanos());

transferTracker.updateLatestLocalFileNameLengthMap(List.of("test"), k -> 1L);
// Sleep for 100ms and then the lag should be within 100ms +/- 20ms
Thread.sleep(100);
assertTrue(Math.abs(transferTracker.getTimeMsLag() - 100) <= 20);
// Sleep for 100ms and then the lag should not be shorter
long span = 100;
Thread.sleep(span);
long lag = transferTracker.getTimeMsLag();
assertTrue("Actual lag [" + lag + "ms] is not expected to be shorter than span [" + span + "ms]", lag >= span);

transferTracker.updateRemoteRefreshTimeMs(transferTracker.getLocalRefreshTimeMs());
transferTracker.updateLocalRefreshTimeMs(currentTimeMsUsingSystemNanos());
long random = randomIntBetween(50, 200);
Thread.sleep(random);
assertTrue(Math.abs(transferTracker.getTimeMsLag() - random) <= 20);
long randomSpan = randomIntBetween(50, 200);
Thread.sleep(randomSpan);
lag = transferTracker.getTimeMsLag();
assertTrue("Actual lag [" + lag + "ms] is not expected to be shorter than span [" + randomSpan + "ms]", lag >= randomSpan);
}

public void testAddUploadBytesStarted() {
Expand Down

0 comments on commit f225b4d

Please sign in to comment.