|
28 | 28 |
|
29 | 29 | import com.google.common.collect.ImmutableMap;
|
30 | 30 | import java.net.URL;
|
| 31 | +import java.time.Duration; |
| 32 | +import java.util.concurrent.CountDownLatch; |
| 33 | +import java.util.concurrent.TimeUnit; |
31 | 34 | import java.util.concurrent.atomic.AtomicInteger;
|
| 35 | +import org.junit.jupiter.api.Assertions; |
32 | 36 | import org.junit.jupiter.api.Test;
|
| 37 | +import org.openqa.selenium.TimeoutException; |
33 | 38 | import org.openqa.selenium.grid.config.CompoundConfig;
|
34 | 39 | import org.openqa.selenium.grid.config.Config;
|
35 | 40 | import org.openqa.selenium.grid.config.MapConfig;
|
36 | 41 | import org.openqa.selenium.grid.server.BaseServerOptions;
|
37 | 42 | import org.openqa.selenium.grid.server.Server;
|
38 | 43 | import org.openqa.selenium.net.PortProber;
|
| 44 | +import org.openqa.selenium.remote.http.ClientConfig; |
39 | 45 | import org.openqa.selenium.remote.http.HttpClient;
|
40 | 46 | import org.openqa.selenium.remote.http.HttpRequest;
|
41 | 47 | import org.openqa.selenium.remote.http.HttpResponse;
|
@@ -141,6 +147,43 @@ void shouldNotBindToHost() {
|
141 | 147 | assertEquals("anyRandomHost", server.getUrl().getHost());
|
142 | 148 | }
|
143 | 149 |
|
| 150 | + @Test |
| 151 | + void doesInterruptPending() throws Exception { |
| 152 | + CountDownLatch interrupted = new CountDownLatch(1); |
| 153 | + Config cfg = new MapConfig(ImmutableMap.of()); |
| 154 | + BaseServerOptions options = new BaseServerOptions(cfg); |
| 155 | + |
| 156 | + Server<?> server = |
| 157 | + new NettyServer( |
| 158 | + options, |
| 159 | + req -> { |
| 160 | + try { |
| 161 | + Thread.sleep(800); |
| 162 | + } catch (InterruptedException ex) { |
| 163 | + interrupted.countDown(); |
| 164 | + } |
| 165 | + return new HttpResponse(); |
| 166 | + }) |
| 167 | + .start(); |
| 168 | + ClientConfig config = |
| 169 | + ClientConfig.defaultConfig() |
| 170 | + .readTimeout(Duration.ofMillis(400)) |
| 171 | + .baseUri(server.getUrl().toURI()); |
| 172 | + |
| 173 | + // provoke a client timeout |
| 174 | + Assertions.assertThrows( |
| 175 | + TimeoutException.class, |
| 176 | + () -> { |
| 177 | + try (HttpClient client = HttpClient.Factory.createDefault().createClient(config)) { |
| 178 | + HttpRequest request = new HttpRequest(DELETE, "/session"); |
| 179 | + request.setHeader("Accept", "*/*"); |
| 180 | + client.execute(request); |
| 181 | + } |
| 182 | + }); |
| 183 | + |
| 184 | + assertTrue(interrupted.await(1000, TimeUnit.MILLISECONDS), "The handling was interrupted"); |
| 185 | + } |
| 186 | + |
144 | 187 | private void outputHeaders(HttpResponse res) {
|
145 | 188 | res.forEachHeader((name, value) -> System.out.printf("%s -> %s\n", name, value));
|
146 | 189 | }
|
|
0 commit comments