Skip to content

Commit 6b07a7f

Browse files
committed
Fix interrupt test for Android
1 parent 686535f commit 6b07a7f

File tree

1 file changed

+10
-4
lines changed
  • binding/android/PicoLLMTestApp/picollm-test-app/src/androidTest/java/ai/picovoice/picollm/testapp

1 file changed

+10
-4
lines changed

binding/android/PicoLLMTestApp/picollm-test-app/src/androidTest/java/ai/picovoice/picollm/testapp/PicoLLMTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.junit.Assert.assertNotNull;
1919
import static org.junit.Assert.assertThrows;
2020
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.fail;
2122

2223
import com.google.gson.Gson;
2324
import com.google.gson.JsonObject;
@@ -527,10 +528,15 @@ public void testInterrupt() throws Exception {
527528
Future<PicoLLMCompletion> resFuture = executor.submit(() ->
528529
picollm.generate(
529530
currentTestData.get("prompt").getAsString(),
530-
new PicoLLMGenerateParams.Builder().build()));
531-
532-
Thread.sleep(500);
533-
picollm.interrupt();
531+
new PicoLLMGenerateParams.Builder()
532+
.setStreamCallback(completion -> {
533+
try {
534+
picollm.interrupt();
535+
} catch (PicoLLMException e) {
536+
fail("Interrupt should not fail.");
537+
}
538+
})
539+
.build()));
534540

535541
PicoLLMCompletion res = resFuture.get();
536542

0 commit comments

Comments
 (0)