2 <script src=
"/js-test-resources/js-test.js"></script>
4 description("Test that WebSockets are not subject to the HTTP connection limit.");
6 window
.jsTestIsAsync
= true;
8 const SOCKETS_TO_OPEN
= 50;
9 // PARALLELISM limits the number of connections we try to open simultaneously.
10 // This avoids triggering the throttling added in http://crrev.com/972963002,
11 // which slows the test down considerably. 4 is the maximum number of
12 // simultaneous pending connections guaranteeed to have zero throttling delay
13 // applied, but parallelism of 2 seems to give the best performance in practice.
14 const PARALLELISM
= 2;
16 var socketsOpened
= 0;
19 function createNewWebSocket()
21 var ws
= new WebSocket("ws://127.0.0.1:8880/echo");
23 ws
.onopen = function() {
24 if (sockets
.length
< SOCKETS_TO_OPEN
) {
28 if (socketsOpened
== SOCKETS_TO_OPEN
) {
29 cleanUpSocketsAndFinish();
32 ws
.onclose = function() {
33 testFailed("unexpected close event");
34 cleanUpSocketsAndFinish();
38 function cleanUpSocketsAndFinish()
40 for (var ws
of sockets
) {
44 shouldBeEqualToNumber("socketsOpened", SOCKETS_TO_OPEN
);
48 for (var i
= 0; i
< PARALLELISM
; ++i
) {