From a3f3ecb34c89d1e7fa30e1173913fc8098546e13 Mon Sep 17 00:00:00 2001 From: Ethan Hou Date: Tue, 4 Aug 2026 14:13:53 +0800 Subject: [PATCH 1/4] fix: Add waitUntil method for asynchronous verification in ByokServiceTests --- .../ui/chat/services/ByokServiceTests.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java index a21e7116..414ae855 100644 --- a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java +++ b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.eclipse.swt.widgets.Display; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -71,8 +72,8 @@ void testConfigureOllama_discoveryFailureKeepsSavedEndpointVisible() { assertThrows(CompletionException.class, () -> byokService.configureOllama(OLLAMA_ENDPOINT).join()); - verify(preferencePage).updateProviderUrlsDisplay(argThat( - providerUrls -> OLLAMA_ENDPOINT.equals(providerUrls.get(OLLAMA_PROVIDER)))); + waitUntil(() -> verify(preferencePage).updateProviderUrlsDisplay(argThat( + providerUrls -> OLLAMA_ENDPOINT.equals(providerUrls.get(OLLAMA_PROVIDER))))); } @Test @@ -86,7 +87,7 @@ void testLoadProviderUrls_ignoresBlankUrlsAndKeepsFirstDuplicate() { byokService.loadProviderUrls().join(); - verify(preferencePage).updateProviderUrlsDisplay(Map.of(OLLAMA_PROVIDER, OLLAMA_ENDPOINT)); + waitUntil(() -> verify(preferencePage).updateProviderUrlsDisplay(Map.of(OLLAMA_PROVIDER, OLLAMA_ENDPOINT))); } @Test @@ -126,7 +127,7 @@ void testDeleteOllamaConfig_removesEndpointBeforeRefresh() { byokService.deleteOllamaConfig().join(); - verify(preferencePage).updateProviderUrlsDisplay(argThat(Map::isEmpty)); + waitUntil(() -> verify(preferencePage).updateProviderUrlsDisplay(argThat(Map::isEmpty))); } private void configureRefreshResponses(List discoveredModels) { @@ -147,4 +148,22 @@ private CompletableFuture completedStatus() { response.setSuccess(true); return CompletableFuture.completedFuture(response); } + + private static void waitUntil(Runnable verification) { + long timeout = System.currentTimeMillis() + 5000; + AssertionError lastError = null; + while (System.currentTimeMillis() < timeout) { + Display.getDefault().syncExec(() -> { + // Allow queued UI Realm callbacks to run before checking the mock. + }); + try { + verification.run(); + return; + } catch (AssertionError e) { + lastError = e; + } + } + throw lastError; + } + } From 68af29784e719db952b8df502ee92a7c91bcf205 Mon Sep 17 00:00:00 2001 From: Ethan Hou Date: Tue, 4 Aug 2026 14:50:26 +0800 Subject: [PATCH 2/4] Address comments. --- .../eclipse/ui/chat/services/ByokServiceTests.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java index 414ae855..2fdc0786 100644 --- a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java +++ b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java @@ -17,11 +17,11 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; +import org.eclipse.swt.widgets.Display; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.eclipse.swt.widgets.Display; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -41,6 +41,8 @@ @ExtendWith(MockitoExtension.class) class ByokServiceTests { + private static final long WAIT_TIMEOUT_MS = 5000; + private static final long WAIT_INTERVAL_MS = 25; private static final String OLLAMA_ENDPOINT = "http://localhost:11434"; private static final String OLLAMA_PROVIDER = ByokModelProvider.OLLAMA.getDisplayName(); @@ -150,7 +152,7 @@ private CompletableFuture completedStatus() { } private static void waitUntil(Runnable verification) { - long timeout = System.currentTimeMillis() + 5000; + long timeout = System.currentTimeMillis() + WAIT_TIMEOUT_MS; AssertionError lastError = null; while (System.currentTimeMillis() < timeout) { Display.getDefault().syncExec(() -> { @@ -162,8 +164,14 @@ private static void waitUntil(Runnable verification) { } catch (AssertionError e) { lastError = e; } + try { + Thread.sleep(WAIT_INTERVAL_MS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new AssertionError("Interrupted while waiting for UI Realm callback", e); + } } - throw lastError; + throw new AssertionError("Timed out waiting for UI Realm callback", lastError); } } From f5f5a9b59d50786d6574181189915597152297bb Mon Sep 17 00:00:00 2001 From: Ethan Hou Date: Tue, 4 Aug 2026 15:14:53 +0800 Subject: [PATCH 3/4] Address comments. --- .../copilot/eclipse/ui/chat/services/ByokServiceTests.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java index 2fdc0786..9a9c47a0 100644 --- a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java +++ b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java @@ -17,7 +17,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; -import org.eclipse.swt.widgets.Display; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -155,9 +154,6 @@ private static void waitUntil(Runnable verification) { long timeout = System.currentTimeMillis() + WAIT_TIMEOUT_MS; AssertionError lastError = null; while (System.currentTimeMillis() < timeout) { - Display.getDefault().syncExec(() -> { - // Allow queued UI Realm callbacks to run before checking the mock. - }); try { verification.run(); return; From 9a5bad724e145e25b6a797c95111ac5507d57cf8 Mon Sep 17 00:00:00 2001 From: Ethan Hou Date: Tue, 4 Aug 2026 16:26:07 +0800 Subject: [PATCH 4/4] fix: Replace waitUntil with timeout verification in ByokServiceTests --- .../ui/chat/services/ByokServiceTests.java | 31 ++++--------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java index 9a9c47a0..93a7c5ac 100644 --- a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java +++ b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/services/ByokServiceTests.java @@ -8,6 +8,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -41,7 +42,6 @@ class ByokServiceTests { private static final long WAIT_TIMEOUT_MS = 5000; - private static final long WAIT_INTERVAL_MS = 25; private static final String OLLAMA_ENDPOINT = "http://localhost:11434"; private static final String OLLAMA_PROVIDER = ByokModelProvider.OLLAMA.getDisplayName(); @@ -73,8 +73,8 @@ void testConfigureOllama_discoveryFailureKeepsSavedEndpointVisible() { assertThrows(CompletionException.class, () -> byokService.configureOllama(OLLAMA_ENDPOINT).join()); - waitUntil(() -> verify(preferencePage).updateProviderUrlsDisplay(argThat( - providerUrls -> OLLAMA_ENDPOINT.equals(providerUrls.get(OLLAMA_PROVIDER))))); + verify(preferencePage, timeout(WAIT_TIMEOUT_MS)).updateProviderUrlsDisplay(argThat( + providerUrls -> OLLAMA_ENDPOINT.equals(providerUrls.get(OLLAMA_PROVIDER)))); } @Test @@ -88,7 +88,8 @@ void testLoadProviderUrls_ignoresBlankUrlsAndKeepsFirstDuplicate() { byokService.loadProviderUrls().join(); - waitUntil(() -> verify(preferencePage).updateProviderUrlsDisplay(Map.of(OLLAMA_PROVIDER, OLLAMA_ENDPOINT))); + verify(preferencePage, timeout(WAIT_TIMEOUT_MS)) + .updateProviderUrlsDisplay(Map.of(OLLAMA_PROVIDER, OLLAMA_ENDPOINT)); } @Test @@ -128,7 +129,7 @@ void testDeleteOllamaConfig_removesEndpointBeforeRefresh() { byokService.deleteOllamaConfig().join(); - waitUntil(() -> verify(preferencePage).updateProviderUrlsDisplay(argThat(Map::isEmpty))); + verify(preferencePage, timeout(WAIT_TIMEOUT_MS)).updateProviderUrlsDisplay(argThat(Map::isEmpty)); } private void configureRefreshResponses(List discoveredModels) { @@ -150,24 +151,4 @@ private CompletableFuture completedStatus() { return CompletableFuture.completedFuture(response); } - private static void waitUntil(Runnable verification) { - long timeout = System.currentTimeMillis() + WAIT_TIMEOUT_MS; - AssertionError lastError = null; - while (System.currentTimeMillis() < timeout) { - try { - verification.run(); - return; - } catch (AssertionError e) { - lastError = e; - } - try { - Thread.sleep(WAIT_INTERVAL_MS); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new AssertionError("Interrupted while waiting for UI Realm callback", e); - } - } - throw new AssertionError("Timed out waiting for UI Realm callback", lastError); - } - }