Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TJ Zhang committed Jun 29, 2024
1 parent e9f4a1c commit a91b9b8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
12 changes: 12 additions & 0 deletions glide-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ fn get_request_timeout(cmd: &Cmd, default_timeout: Duration) -> RedisResult<Opti
.position(b"BLOCK")
.map(|idx| get_timeout_from_cmd_arg(cmd, idx + 1, TimeUnit::Milliseconds))
.unwrap_or(Ok(RequestTimeoutOption::ClientConfig)),
b"WAIT" => get_timeout_from_cmd_arg(cmd, 1, TimeUnit::Milliseconds),
_ => Ok(RequestTimeoutOption::ClientConfig),
}?;

Expand Down Expand Up @@ -736,6 +737,17 @@ mod tests {
0.857 + BLOCKING_CMD_TIMEOUT_EXTENSION
))
);

let mut cmd = Cmd::new();
cmd.arg("WAIT").arg("500");
let result = get_request_timeout(&cmd, Duration::from_millis(100));
assert!(result.is_ok());
assert_eq!(
result.unwrap(),
Some(Duration::from_secs_f64(
0.5 + BLOCKING_CMD_TIMEOUT_EXTENSION
))
);
}

#[test]
Expand Down
33 changes: 33 additions & 0 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7576,4 +7576,37 @@ public void geosearchstore(BaseClient client) {
.get());
assertInstanceOf(RequestException.class, requestException2.getCause());
}

@SneakyThrows
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("getClients")
public void waitTest(BaseClient client) {
// setup
String key = UUID.randomUUID().toString();
long numreplicas = 1L;
long timeout = 400L;

assertEquals(OK, client.set(key, "value").get());
assertTrue(client.wait(numreplicas, timeout).get() >= (client instanceof RedisClient ? 0 : 1));

// command should fail on a negative timeout value
ExecutionException executionException =
assertThrows(ExecutionException.class, () -> client.wait(1L, -1L).get());
assertInstanceOf(RequestException.class, executionException.getCause());
}

@SneakyThrows
@ParameterizedTest(autoCloseArguments = false)
@MethodSource("getClients")
public void wait_timeout_check(BaseClient client) {
// create new client with default request timeout (250 millis)
try (var testClient =
client instanceof RedisClient
? RedisClient.CreateClient(commonClientConfig().build()).get()
: RedisClusterClient.CreateClient(commonClusterClientConfig().build()).get()) {

// ensure that commands doesn't time out even if timeout > request timeout
assertEquals((client instanceof RedisClient ? 0 : 1), testClient.wait(1L, 300L).get());
}
}
}
17 changes: 0 additions & 17 deletions java/integTest/src/test/java/glide/cluster/CommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1846,21 +1846,4 @@ public void sort() {
.get());
assertArrayEquals(key2DescendingListSubset, clusterClient.lrange(key3, 0, -1).get());
}

@SneakyThrows
@Test
public void waitTest() {
// setup
String key = UUID.randomUUID().toString();
long numreplicas = 1L;
long timeout = 1000L;

assertEquals(OK, clusterClient.set(key, "value").get());
assertTrue(clusterClient.wait(numreplicas, timeout).get() >= 1);

// command should fail on a negative timeout value
ExecutionException executionException =
assertThrows(ExecutionException.class, () -> clusterClient.wait(1L, -1L).get());
assertInstanceOf(RequestException.class, executionException.getCause());
}
}
17 changes: 0 additions & 17 deletions java/integTest/src/test/java/glide/standalone/CommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1032,21 +1032,4 @@ public void sort() {
.get());
assertArrayEquals(namesSortedByAge, regularClient.lrange(storeKey, 0, -1).get());
}

@SneakyThrows
@Test
public void waitTest() {
// setup
String key = UUID.randomUUID().toString();
long numreplicas = 1L;
long timeout = 1000L;

assertEquals(OK, regularClient.set(key, "value").get());
assertTrue(regularClient.wait(numreplicas, timeout).get() >= 0);

// command should fail on a negative timeout value
ExecutionException executionException =
assertThrows(ExecutionException.class, () -> regularClient.wait(1L, -1L).get());
assertInstanceOf(RequestException.class, executionException.getCause());
}
}

0 comments on commit a91b9b8

Please sign in to comment.