|
15 | 15 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
16 | 16 | import static org.junit.jupiter.api.Assertions.assertNull;
|
17 | 17 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
| 18 | +import static org.junit.jupiter.api.Assumptions.assumeTrue; |
18 | 19 |
|
19 | 20 | import java.io.BufferedReader;
|
20 | 21 | import java.io.InputStreamReader;
|
21 | 22 | import java.lang.ProcessBuilder.Redirect;
|
22 | 23 | import java.nio.file.Files;
|
23 | 24 | import java.nio.file.Path;
|
24 | 25 | import java.rmi.NotBoundException;
|
| 26 | +import java.rmi.RemoteException; |
25 | 27 | import java.rmi.registry.LocateRegistry;
|
26 | 28 | import java.rmi.registry.Registry;
|
27 | 29 | import java.util.List;
|
|
51 | 53 | */
|
52 | 54 | public class Test_org_eclipse_swt_dnd_Clipboard {
|
53 | 55 |
|
| 56 | + private static final int DEFAULT_TIMEOUT_MS = 10000; |
54 | 57 | @TempDir
|
55 | 58 | static Path tempFolder;
|
56 | 59 | static int uniqueId = 1;
|
@@ -168,16 +171,40 @@ private void startRemoteClipboardCommands() throws Exception {
|
168 | 171 | throw new RuntimeException("Failed to get port");
|
169 | 172 | });
|
170 | 173 | assertNotEquals(0, port);
|
171 |
| - Registry reg = LocateRegistry.getRegistry("127.0.0.1", port); |
172 |
| - long stopTime = System.currentTimeMillis() + 10000; |
173 |
| - do { |
| 174 | + try { |
| 175 | + Registry reg = LocateRegistry.getRegistry("127.0.0.1", port); |
| 176 | + long stopTime = System.currentTimeMillis() + DEFAULT_TIMEOUT_MS; |
| 177 | + do { |
| 178 | + try { |
| 179 | + remote = (ClipboardCommands) reg.lookup(ClipboardCommands.ID); |
| 180 | + break; |
| 181 | + } catch (NotBoundException e) { |
| 182 | + // try again because the remote app probably hasn't bound yet |
| 183 | + } |
| 184 | + } while (System.currentTimeMillis() < stopTime); |
| 185 | + } catch (RemoteException e) { |
| 186 | + |
| 187 | + Integer exitValue = null; |
| 188 | + boolean waitFor = false; |
174 | 189 | try {
|
175 |
| - remote = (ClipboardCommands) reg.lookup(ClipboardCommands.ID); |
176 |
| - break; |
177 |
| - } catch (NotBoundException e) { |
178 |
| - // try again because the remote app probably hasn't bound yet |
| 190 | + waitFor = remoteClipboardProcess.waitFor(5, TimeUnit.SECONDS); |
| 191 | + if (waitFor) { |
| 192 | + exitValue = remoteClipboardProcess.exitValue(); |
| 193 | + } |
| 194 | + } catch (InterruptedException e1) { |
| 195 | + Thread.interrupted(); |
179 | 196 | }
|
180 |
| - } while (System.currentTimeMillis() < stopTime); |
| 197 | + |
| 198 | + String message = "Failed to get remote clipboards command, this seems to happen on macOS on I-build tests. Exception: " |
| 199 | + + e.toString() + " waitFor: " + waitFor + " exitValue: " + exitValue; |
| 200 | + |
| 201 | + // Give some diagnostic information to help track down why this fails on build |
| 202 | + // machine. We only hard error on Linux, for other platforms we allow test to |
| 203 | + // just be skipped until we track down what is causing |
| 204 | + // https://github.com/eclipse-platform/eclipse.platform.swt/issues/2553 |
| 205 | + assumeTrue(SwtTestUtil.isGTK, message); |
| 206 | + throw new RuntimeException(message, e); |
| 207 | + } |
181 | 208 | assertNotNull(remote);
|
182 | 209 |
|
183 | 210 | // Run a no-op on the Swing event loop so that we know it is idle
|
@@ -318,7 +345,7 @@ public interface ExceptionalSupplier<T> {
|
318 | 345 | * the thread completes, or until a timeout is reached.
|
319 | 346 | */
|
320 | 347 | private <T> T runOperationInThread(ExceptionalSupplier<T> supplier) throws RuntimeException {
|
321 |
| - return runOperationInThread(2000, supplier); |
| 348 | + return runOperationInThread(DEFAULT_TIMEOUT_MS, supplier); |
322 | 349 | }
|
323 | 350 |
|
324 | 351 | /**
|
|
0 commit comments