|
5 | 5 | import io.github.easy4j.opencli.OpenCliInvocationContext.SiteSession; |
6 | 6 | import io.github.easy4j.opencli.OpenCliInvocationContext.WindowMode; |
7 | 7 | import io.github.easy4j.opencli.OpenCliProperties; |
| 8 | +import io.github.easy4j.opencli.exception.OpenCliNonZeroExitException; |
8 | 9 | import java.io.File; |
9 | 10 | import java.io.InputStream; |
10 | 11 | import java.nio.charset.StandardCharsets; |
@@ -33,6 +34,29 @@ void concurrentInvocationsKeepTheirProfileAndWindow() throws Exception { |
33 | 34 | } |
34 | 35 | } |
35 | 36 |
|
| 37 | + @Test |
| 38 | + void failedInvocationKeepsItsContextWithoutChangingConcurrentOrDefaultCalls() throws Exception { |
| 39 | + OpenCliProperties properties = properties(); |
| 40 | + properties.setInvocationDefaults(OpenCliInvocationContext.builder().profile("profile-default") |
| 41 | + .window(WindowMode.FOREGROUND).build()); |
| 42 | + ExecutorService pool = Executors.newFixedThreadPool(2); |
| 43 | + try (OpenCliClient client = new OpenCliClient(properties)) { |
| 44 | + Future<OpenCliNonZeroExitException> failure = pool.submit(() -> assertThrows( |
| 45 | + OpenCliNonZeroExitException.class, () -> state(client, "profile-failure", WindowMode.BACKGROUND))); |
| 46 | + Future<String> success = pool.submit(() -> state(client, "profile-success", WindowMode.FOREGROUND)); |
| 47 | + |
| 48 | + assertEquals("--profile|profile-success|browser|session-a|--window|foreground|state", |
| 49 | + success.get(12, TimeUnit.SECONDS)); |
| 50 | + assertEquals("--profile|profile-failure|browser|session-a|--window|background|state", |
| 51 | + failure.get(12, TimeUnit.SECONDS).getPartialResult().getStdout()); |
| 52 | + assertEquals("--profile|profile-default|browser|session-a|--window|foreground|state", |
| 53 | + client.invokeDiscovered(OpenCliHelpScope.BROWSER_STATE, "opencli browser <session> state", |
| 54 | + "session-a", null, null).getStdout()); |
| 55 | + } finally { |
| 56 | + pool.shutdownNow(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
36 | 60 | @Test |
37 | 61 | void explicitFalseOverridesClientDefaultWithinVerifiedBrowserAdapter() { |
38 | 62 | OpenCliProperties properties = properties(); |
@@ -99,6 +123,9 @@ public static void main(String[] args) throws Exception { |
99 | 123 | System.exit(4); |
100 | 124 | } |
101 | 125 | System.out.print(String.join("|", args)); |
| 126 | + if (argv.startsWith("--profile profile-failure ")) { |
| 127 | + System.exit(7); |
| 128 | + } |
102 | 129 | } |
103 | 130 | } |
104 | 131 |
|
|
0 commit comments