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 (opensearch-project#15187)


Signed-off-by: Lukáš Vlček <[email protected]>
  • Loading branch information
lukas-vlcek authored and akolarkunnu committed Sep 10, 2024
1 parent 0d85636 commit 8086bb8
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 8086bb8

Please sign in to comment.