Skip to content

Commit

Permalink
Don't use awaitility
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jan 8, 2024
1 parent bc5f701 commit a093961
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:${junitVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${junitVersion}")
testImplementation("org.assertj:assertj-core:3.25.1")
testImplementation("org.awaitility:awaitility:4.2.0")
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.stefanbratanov.chatjpt;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertThrows;

import io.github.stefanbratanov.chatjpt.SubmitToolOutputsRequest.ToolOutput;
Expand Down Expand Up @@ -259,16 +258,13 @@ public void testRunsClient() {
.isEqualTo(run);

// wait for the run to complete, fail or expire
await()
.pollInterval(Duration.ofSeconds(5))
.atMost(Duration.ofMinutes(1))
.until(
() -> {
String status = runsClient.retrieveRun(thread.id(), run.id()).status();
return status.equals("completed")
|| status.equals("failed")
|| status.equals("expired");
});
awaitCondition(
() -> {
String status = runsClient.retrieveRun(thread.id(), run.id()).status();
return status.equals("completed") || status.equals("failed") || status.equals("expired");
},
Duration.ofSeconds(5),
Duration.ofMinutes(1));

// retrieve run steps
List<ThreadRunStep> runSteps =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;

public class ChatJPTIntegrationTestBase {
Expand Down Expand Up @@ -46,4 +50,27 @@ protected static Path getTestResource(String resource) {
throw new RuntimeException(ex);
}
}

protected void awaitCondition(
Supplier<Boolean> condition, Duration pollingInterval, Duration timeout) {

boolean isDone = false;
long startTime = System.currentTimeMillis();
long endTime = startTime + timeout.toMillis();

while (System.currentTimeMillis() < endTime && !isDone) {
isDone = condition.get();
if (!isDone) {
try {
TimeUnit.MILLISECONDS.sleep(pollingInterval.toMillis());
} catch (InterruptedException ex) {
Assertions.fail(ex);
}
}
}

if (!isDone) {
Assertions.fail("The condition was not satisfied within the time limit.");
}
}
}

0 comments on commit a093961

Please sign in to comment.