Best JavaScript code snippet using wpt
server.harness.test.js
Source:server.harness.test.js
...94 expect(l.badClientMessage.mock.calls.length).toBe(0);95 expect(l.transportError.mock.calls.length).toBe(0);96 });97 });98 describe("the harn.getServerState() and expect(x).toHaveState(y) functions", () => {99 describe("should handle invalid root keys correctly", () => {100 it("should throw if root keys are invalid", () => {101 const harn = harness();102 const result = harness.toHaveState(harn.server, {});103 expect(result.pass).toBe(false);104 expect(result.message()).toEqual(105 "expected root keys to be valid, but they weren't"106 );107 });108 });109 describe("should handle ._options correctly", () => {110 let harn;111 beforeEach(() => {112 harn = harness({113 handshakeMs: 123,114 terminationMs: 456115 });116 });117 it("should represent the state correctly", () => {118 const state = harn.getServerState();119 expect(state._options).toEqual({120 handshakeMs: 123,121 terminationMs: 456122 });123 });124 it("should compare the state correctly - match", () => {125 const state = harn.getServerState();126 expect(harn.server).toHaveState(state);127 });128 it("should compare the state correctly - mismatch", () => {129 const state = harn.getServerState();130 state._options.junk = 123;131 const result = harness.toHaveState(harn.server, state);132 expect(result.pass).toBe(false);133 expect(result.message()).toEqual(134 "expected ._options to match, but they didn't"135 );136 });137 });138 describe("should handle ._transportWrapper (and state) correctly", () => {139 let harn;140 beforeEach(() => {141 harn = harness();142 });143 it("should represent the state correctly", () => {144 const state = harn.getServerState();145 expect(state._transportWrapper).toBe(harn.server._transportWrapper);146 expect(state._transportWrapperState).toBe("stopped");147 });148 it("should compare the state correctly - match", () => {149 const state = harn.getServerState();150 expect(harn.server).toHaveState(state);151 });152 it("should compare the state correctly - mismatched object ref", () => {153 const state = harn.getServerState();154 state._transportWrapper = {};155 const result = harness.toHaveState(harn.server, state);156 expect(result.pass).toBe(false);157 expect(result.message()).toEqual(158 "expected transport wrapper objects to match, but they didn't"159 );160 });161 it("should compare the state correctly - mismatched transport state", () => {162 const state = harn.getServerState();163 state._transportWrapperState = "starting";164 const result = harness.toHaveState(harn.server, state);165 expect(result.pass).toBe(false);166 expect(result.message()).toEqual(167 "expected transport wrapper states to match, but they didn't"168 );169 });170 });171 describe("should handle ._clientIds correctly", () => {172 let harn;173 beforeEach(() => {174 harn = harness();175 harn.server._clientIds = {176 cid1: "tcid1",177 cid2: "tcid2"178 };179 });180 it("should represent the state correctly", () => {181 const state = harn.getServerState();182 expect(state._clientIds).toEqual({183 cid1: "tcid1",184 cid2: "tcid2"185 });186 });187 it("should compare the state correctly - match", () => {188 const state = harn.getServerState();189 expect(harn.server).toHaveState(state);190 });191 it("should compare the state correctly - mismatch", () => {192 const state = harn.getServerState();193 state._clientIds.junk = 123;194 const result = harness.toHaveState(harn.server, state);195 expect(result.pass).toBe(false);196 expect(result.message()).toEqual(197 "expected ._clientIds to match, but they didn't"198 );199 });200 });201 describe("should handle ._transportClientIds correctly", () => {202 let harn;203 beforeEach(() => {204 harn = harness();205 harn.server._transportClientIds = {206 tcid1: "cid1",207 tcid2: "cid2"208 };209 });210 it("should represent the state correctly", () => {211 const state = harn.getServerState();212 expect(state._transportClientIds).toEqual({213 tcid1: "cid1",214 tcid2: "cid2"215 });216 });217 it("should compare the state correctly - match", () => {218 const state = harn.getServerState();219 expect(harn.server).toHaveState(state);220 });221 it("should compare the state correctly - mismatch", () => {222 const state = harn.getServerState();223 state._transportClientIds.junk = 123;224 const result = harness.toHaveState(harn.server, state);225 expect(result.pass).toBe(false);226 expect(result.message()).toEqual(227 "expected ._transportClientIds to match, but they didn't"228 );229 });230 });231 describe("should handle ._handshakeTimers correctly", () => {232 let harn;233 beforeEach(() => {234 harn = harness();235 harn.server._handshakeTimers = {236 cid1: 123,237 cid2: 456238 };239 });240 it("should represent the state correctly", () => {241 const state = harn.getServerState();242 expect(state._handshakeTimers).toEqual({243 cid1: 123,244 cid2: 456245 });246 });247 it("should compare the state correctly - match with identical timer ids", () => {248 const state = harn.getServerState();249 expect(harn.server).toHaveState(state);250 });251 it("should compare the state correctly - match with different timer ids", () => {252 const state = harn.getServerState();253 state._handshakeTimers = {254 cid1: 888,255 cid2: 999256 };257 expect(harn.server).toHaveState(state);258 });259 it("should compare the state correctly - mismatched key", () => {260 const state = harn.getServerState();261 state._handshakeTimers.junk = 123;262 const result = harness.toHaveState(harn.server, state);263 expect(result.pass).toBe(false);264 expect(result.message()).toEqual(265 "expected ._handshakeTimers keys to match, but they didn't"266 );267 });268 it("should compare the state correctly - mismatched value", () => {269 const state = harn.getServerState();270 state._handshakeTimers.cid1 = "junk";271 const result = harness.toHaveState(harn.server, state);272 expect(result.pass).toBe(false);273 expect(result.message()).toEqual(274 "expected ._handshakeTimers values to match, but they didn't"275 );276 });277 });278 describe("should handle ._handshakeStatus correctly", () => {279 let harn;280 beforeEach(() => {281 harn = harness();282 harn.server._handshakeStatus = {283 cid1: "waiting",284 cid2: "processing"285 };286 });287 it("should represent the state correctly", () => {288 const state = harn.getServerState();289 expect(state._handshakeStatus).toEqual({290 cid1: "waiting",291 cid2: "processing"292 });293 });294 it("should compare the state correctly - match", () => {295 const state = harn.getServerState();296 expect(harn.server).toHaveState(state);297 });298 it("should compare the state correctly - mismatched key", () => {299 const state = harn.getServerState();300 state._handshakeStatus.junk = 123;301 const result = harness.toHaveState(harn.server, state);302 expect(result.pass).toBe(false);303 expect(result.message()).toEqual(304 "expected ._handshakeStatus to match, but they didn't"305 );306 });307 });308 describe("should handle ._handshakeResponses (and state) correctly", () => {309 let harn;310 let hsr1;311 let hsr2;312 beforeEach(() => {313 harn = harness();314 hsr1 = {315 _server: {},316 _handshakeRequest: { clientId: "cid1" },317 _appResponded: true,318 _neutralized: false319 };320 hsr2 = {321 _server: {},322 _handshakeRequest: { clientId: "cid2" },323 _appResponded: false,324 _neutralized: true325 };326 harn.server._handshakeResponses = {327 cid1: hsr1,328 cid2: hsr2329 };330 });331 it("should represent the state correctly", () => {332 const state = harn.getServerState();333 expect(_.keys(state._handshakeResponses).sort()).toEqual([334 "cid1",335 "cid2"336 ]);337 expect(state._handshakeResponses.cid1).toBe(hsr1);338 expect(state._handshakeResponses.cid2).toBe(hsr2);339 expect(_.keys(state._handshakeResponseStates).sort()).toEqual([340 "cid1",341 "cid2"342 ]);343 expect(check.object(state._handshakeResponseStates.cid1)).toBe(true);344 expect(state._handshakeResponseStates.cid1._server).toBe(hsr1._server);345 expect(state._handshakeResponseStates.cid1._handshakeRequest).toEqual({346 clientId: "cid1"347 });348 expect(state._handshakeResponseStates.cid1._appResponded).toBe(true);349 expect(state._handshakeResponseStates.cid1._neutralized).toBe(false);350 expect(check.object(state._handshakeResponseStates.cid2)).toBe(true);351 expect(state._handshakeResponseStates.cid2._server).toBe(hsr2._server);352 expect(state._handshakeResponseStates.cid2._handshakeRequest).toEqual({353 clientId: "cid2"354 });355 expect(state._handshakeResponseStates.cid2._appResponded).toBe(false);356 expect(state._handshakeResponseStates.cid2._neutralized).toBe(true);357 });358 it("should compare the state correctly - match", () => {359 const state = harn.getServerState();360 expect(harn.server).toHaveState(state);361 });362 it("should compare the state correctly - mismatched ._handshakeResponses key", () => {363 const state = harn.getServerState();364 state._handshakeResponses.junk = {};365 const result = harness.toHaveState(harn.server, state);366 expect(result.pass).toBe(false);367 expect(result.message()).toEqual(368 "expected ._handshakeResponses keys to match, but they didn't"369 );370 });371 it("should compare the state correctly - mismatched ._handshakeResponses[cid] value", () => {372 const state = harn.getServerState();373 state._handshakeResponses.cid1 = {};374 const result = harness.toHaveState(harn.server, state);375 expect(result.pass).toBe(false);376 expect(result.message()).toEqual(377 "expected ._handshakeResponses values to match, but they didn't"378 );379 });380 it("should compare the state correctly - mismatched ._handshakeResponseStates key", () => {381 const state = harn.getServerState();382 state._handshakeResponseStates.junk = {};383 const result = harness.toHaveState(harn.server, state);384 expect(result.pass).toBe(false);385 expect(result.message()).toEqual(386 "expected ._handshakeResponseStates keys to match, but they didn't"387 );388 });389 it("should compare the state correctly - mismatched ._handshakeResponseStates[cid] key", () => {390 const state = harn.getServerState();391 state._handshakeResponseStates.cid1.junk = 123;392 const result = harness.toHaveState(harn.server, state);393 expect(result.pass).toBe(false);394 expect(result.message()).toEqual(395 "expected ._handshakeResponseStates[cid] keys to be valid, but they weren't"396 );397 });398 it("should compare the state correctly - mismatched ._handshakeResponseStates[cid]._server", () => {399 const state = harn.getServerState();400 state._handshakeResponseStates.cid1._server = {};401 const result = harness.toHaveState(harn.server, state);402 expect(result.pass).toBe(false);403 expect(result.message()).toEqual(404 "expected ._handshakeResponseStates[cid] values to match, but they didn't"405 );406 });407 it("should compare the state correctly - mismatched ._handshakeResponseStates[cid]._handshakeRequest", () => {408 const state = harn.getServerState();409 state._handshakeResponseStates.cid1._handshakeRequest = {410 clientId: "junk"411 };412 const result = harness.toHaveState(harn.server, state);413 expect(result.pass).toBe(false);414 expect(result.message()).toEqual(415 "expected ._handshakeResponseStates[cid] values to match, but they didn't"416 );417 });418 it("should compare the state correctly - mismatched ._handshakeResponseStates[cid]._appResponded", () => {419 const state = harn.getServerState();420 state._handshakeResponseStates.cid1._appResponded = false;421 const result = harness.toHaveState(harn.server, state);422 expect(result.pass).toBe(false);423 expect(result.message()).toEqual(424 "expected ._handshakeResponseStates[cid] values to match, but they didn't"425 );426 });427 it("should compare the state correctly - mismatched ._handshakeResponseStates[cid]._neutralized", () => {428 const state = harn.getServerState();429 state._handshakeResponseStates.cid1._neutralized = true;430 const result = harness.toHaveState(harn.server, state);431 expect(result.pass).toBe(false);432 expect(result.message()).toEqual(433 "expected ._handshakeResponseStates[cid] values to match, but they didn't"434 );435 });436 });437 describe("should handle ._actionResponses (and state) correctly", () => {438 let harn;439 let ar11;440 let ar12;441 let ar21;442 beforeEach(() => {443 harn = harness();444 ar11 = {445 _server: {},446 _actionRequest: {447 clientId: "cid1",448 _actionCallbackId: "acb11",449 actionName: "action11",450 actionArgs: { action: "args11" }451 },452 _appResponded: true,453 _neutralized: true454 };455 ar12 = {456 _server: {},457 _actionRequest: {458 clientId: "cid1",459 _actionCallbackId: "acb12",460 actionName: "action12",461 actionArgs: { action: "args12" }462 },463 _appResponded: true,464 _neutralized: false465 };466 ar21 = {467 _server: {},468 _actionRequest: {469 clientId: "cid2",470 _actionCallbackId: "acb21",471 actionName: "action21",472 actionArgs: { action: "args21" }473 },474 _appResponded: false,475 _neutralized: true476 };477 harn.server._actionResponses = {478 cid1: { acb11: ar11, acb12: ar12 },479 cid2: { acb21: ar21 }480 };481 });482 it("should represent the state correctly", () => {483 const state = harn.getServerState();484 expect(_.keys(state._actionResponses).sort()).toEqual(["cid1", "cid2"]);485 expect(_.keys(state._actionResponses.cid1).sort()).toEqual([486 "acb11",487 "acb12"488 ]);489 expect(_.keys(state._actionResponses.cid2).sort()).toEqual(["acb21"]);490 expect(state._actionResponses.cid1.acb11).toBe(ar11);491 expect(state._actionResponses.cid1.acb12).toBe(ar12);492 expect(state._actionResponses.cid2.acb21).toBe(ar21);493 expect(_.keys(state._actionResponseStates).sort()).toEqual([494 "cid1",495 "cid2"496 ]);497 expect(_.keys(state._actionResponseStates.cid1).sort()).toEqual([498 "acb11",499 "acb12"500 ]);501 expect(_.keys(state._actionResponseStates.cid2).sort()).toEqual([502 "acb21"503 ]);504 expect(state._actionResponseStates.cid1.acb11._server).toBe(505 ar11._server506 );507 expect(state._actionResponseStates.cid1.acb11._actionRequest).toEqual({508 clientId: "cid1",509 _actionCallbackId: "acb11",510 actionName: "action11",511 actionArgs: { action: "args11" }512 });513 expect(state._actionResponseStates.cid1.acb11._appResponded).toBe(true);514 expect(state._actionResponseStates.cid1.acb11._neutralized).toBe(true);515 expect(state._actionResponseStates.cid1.acb12._server).toBe(516 ar12._server517 );518 expect(state._actionResponseStates.cid1.acb12._actionRequest).toEqual({519 clientId: "cid1",520 _actionCallbackId: "acb12",521 actionName: "action12",522 actionArgs: { action: "args12" }523 });524 expect(state._actionResponseStates.cid1.acb12._appResponded).toBe(true);525 expect(state._actionResponseStates.cid1.acb12._neutralized).toBe(false);526 expect(state._actionResponseStates.cid2.acb21._server).toBe(527 ar21._server528 );529 expect(state._actionResponseStates.cid2.acb21._actionRequest).toEqual({530 clientId: "cid2",531 _actionCallbackId: "acb21",532 actionName: "action21",533 actionArgs: { action: "args21" }534 });535 expect(state._actionResponseStates.cid2.acb21._appResponded).toBe(536 false537 );538 expect(state._actionResponseStates.cid2.acb21._neutralized).toBe(true);539 });540 it("should compare the state correctly - match", () => {541 const state = harn.getServerState();542 expect(harn.server).toHaveState(state);543 });544 it("should compare the state correctly - mismatched ._actionResponses key", () => {545 const state = harn.getServerState();546 state._actionResponses.junk = {};547 const result = harness.toHaveState(harn.server, state);548 expect(result.pass).toBe(false);549 expect(result.message()).toEqual(550 "expected ._actionResponses keys to match, but they didn't"551 );552 });553 it("should compare the state correctly - mismatched ._actionResponses[cid] key", () => {554 const state = harn.getServerState();555 state._actionResponses.cid1.junk = {};556 const result = harness.toHaveState(harn.server, state);557 expect(result.pass).toBe(false);558 expect(result.message()).toEqual(559 "expected ._actionResponses[cid] keys to match, but they didn't"560 );561 });562 it("should compare the state correctly - mismatched ._actionResponses[cid] value", () => {563 const state = harn.getServerState();564 state._actionResponses.cid1.acb11 = {};565 const result = harness.toHaveState(harn.server, state);566 expect(result.pass).toBe(false);567 expect(result.message()).toEqual(568 "expected ._actionResponses[cid] values to match, but they didn't"569 );570 });571 it("should compare the state correctly - mismatched ._actionResponseStates key", () => {572 const state = harn.getServerState();573 state._actionResponseStates.junk = {};574 const result = harness.toHaveState(harn.server, state);575 expect(result.pass).toBe(false);576 expect(result.message()).toEqual(577 "expected ._actionResponseStates keys to match, but they didn't"578 );579 });580 it("should compare the state correctly - mismatched ._actionResponseStates[cid] key", () => {581 const state = harn.getServerState();582 state._actionResponseStates.cid1.junk = {};583 const result = harness.toHaveState(harn.server, state);584 expect(result.pass).toBe(false);585 expect(result.message()).toEqual(586 "expected ._actionResponseStates[cid] keys to match, but they didn't"587 );588 });589 it("should compare the state correctly - mismatched ._actionResponseStates[cid][acb] key", () => {590 const state = harn.getServerState();591 state._actionResponseStates.cid1.acb11.junk = 123;592 const result = harness.toHaveState(harn.server, state);593 expect(result.pass).toBe(false);594 expect(result.message()).toEqual(595 "expected ._actionResponseStates[cid][acb] keys to be valid, but they weren't"596 );597 });598 it("should compare the state correctly - mismatched ._actionResponseStates[cid][acb]._server", () => {599 const state = harn.getServerState();600 state._actionResponseStates.cid1.acb11._server = {};601 const result = harness.toHaveState(harn.server, state);602 expect(result.pass).toBe(false);603 expect(result.message()).toEqual(604 "expected ._actionResponseStates[cid][acb] values to match, but they didn't"605 );606 });607 it("should compare the state correctly - mismatched ._actionResponseStates[cid][acb]._actionRequest", () => {608 const state = harn.getServerState();609 state._actionResponseStates.cid1.acb11._actionRequest = {610 clientId: "junk",611 _actionCallbackId: "junk",612 actionName: "junk",613 actionArgs: { action: "junk" }614 };615 const result = harness.toHaveState(harn.server, state);616 expect(result.pass).toBe(false);617 expect(result.message()).toEqual(618 "expected ._actionResponseStates[cid][acb] values to match, but they didn't"619 );620 });621 it("should compare the state correctly - mismatched ._actionResponseStates[cid][acb]._appResponded", () => {622 const state = harn.getServerState();623 state._actionResponseStates.cid1.acb11._appResponded = false;624 const result = harness.toHaveState(harn.server, state);625 expect(result.pass).toBe(false);626 expect(result.message()).toEqual(627 "expected ._actionResponseStates[cid][acb] values to match, but they didn't"628 );629 });630 it("should compare the state correctly - mismatched ._actionResponseStates[cid][acb]._neutralized", () => {631 const state = harn.getServerState();632 state._actionResponseStates.cid1.acb11._neutralized = false;633 const result = harness.toHaveState(harn.server, state);634 expect(result.pass).toBe(false);635 expect(result.message()).toEqual(636 "expected ._actionResponseStates[cid][acb] values to match, but they didn't"637 );638 });639 });640 describe("should handle ._clientFeedStates correctly", () => {641 let harn;642 beforeEach(() => {643 harn = harness();644 harn.server._clientFeedStates = {645 cid1: {646 ser1: "opening",647 ser2: "open"648 },649 cid2: {650 ser1: "closing"651 }652 };653 });654 it("should represent the state correctly", () => {655 const state = harn.getServerState();656 expect(state._clientFeedStates).toEqual({657 cid1: {658 ser1: "opening",659 ser2: "open"660 },661 cid2: {662 ser1: "closing"663 }664 });665 });666 it("should compare the state correctly - match", () => {667 const state = harn.getServerState();668 expect(harn.server).toHaveState(state);669 });670 it("should compare the state correctly - mismatch", () => {671 const state = harn.getServerState();672 state._clientFeedStates.junk = {};673 const result = harness.toHaveState(harn.server, state);674 expect(result.pass).toBe(false);675 expect(result.message()).toEqual(676 "expected ._clientFeedStates to match, but they didn't"677 );678 });679 });680 describe("should handle ._feedClientStates correctly", () => {681 let harn;682 beforeEach(() => {683 harn = harness();684 harn.server._feedClientStates = {685 ser1: {686 cid1: "opening",687 cid2: "closing"688 },689 ser2: {690 cid1: "open"691 }692 };693 });694 it("should represent the state correctly", () => {695 const state = harn.getServerState();696 expect(state._feedClientStates).toEqual({697 ser1: {698 cid1: "opening",699 cid2: "closing"700 },701 ser2: {702 cid1: "open"703 }704 });705 });706 it("should compare the state correctly - match", () => {707 const state = harn.getServerState();708 expect(harn.server).toHaveState(state);709 });710 it("should compare the state correctly - mismatch", () => {711 const state = harn.getServerState();712 state._feedClientStates.junk = {};713 const result = harness.toHaveState(harn.server, state);714 expect(result.pass).toBe(false);715 expect(result.message()).toEqual(716 "expected ._feedClientStates to match, but they didn't"717 );718 });719 });720 describe("should handle ._terminationTimers correctly", () => {721 let harn;722 beforeEach(() => {723 harn = harness();724 harn.server._terminationTimers = {725 cid1: {726 ser1: 123,727 ser2: 456728 },729 cid2: {730 ser1: 789731 }732 };733 });734 it("should represent the state correctly", () => {735 const state = harn.getServerState();736 expect(state._terminationTimers).toEqual({737 cid1: {738 ser1: 123,739 ser2: 456740 },741 cid2: {742 ser1: 789743 }744 });745 });746 it("should compare the state correctly - match with identical timer ids", () => {747 const state = harn.getServerState();748 expect(harn.server).toHaveState(state);749 });750 it("should compare the state correctly - match with different timer ids", () => {751 const state = harn.getServerState();752 state._terminationTimers.cid1.ser1 = 999;753 expect(harn.server).toHaveState(state);754 });755 it("should compare the state correctly - mismatched ._terminationTimers key", () => {756 const state = harn.getServerState();757 state._terminationTimers.junk = {};758 const result = harness.toHaveState(harn.server, state);759 expect(result.pass).toBe(false);760 expect(result.message()).toEqual(761 "expected ._terminationTimers keys to match, but they didn't"762 );763 });764 it("should compare the state correctly - mismatched ._terminationTimers[cid] key", () => {765 const state = harn.getServerState();766 state._terminationTimers.cid1.junk = {};767 const result = harness.toHaveState(harn.server, state);768 expect(result.pass).toBe(false);769 expect(result.message()).toEqual(770 "expected ._terminationTimers[cid] keys to match, but they didn't"771 );772 });773 it("should compare the state correctly - mismatched ._terminationTimers[cid] value", () => {774 const state = harn.getServerState();775 state._terminationTimers.cid1.ser1 = "junk";776 const result = harness.toHaveState(harn.server, state);777 expect(result.pass).toBe(false);778 expect(result.message()).toEqual(779 "expected ._terminationTimers[cid] values to match, but they didn't"780 );781 });782 });783 describe("should handle ._feedOpenResponses (and state) correctly", () => {784 let harn;785 let for11;786 let for12;787 let for21;788 beforeEach(() => {789 harn = harness();790 for11 = {791 _server: {},792 _feedOpenRequest: {793 clientId: "cid1",794 feedName: "feed1",795 feedArgs: { feed: "args1" }796 },797 _appResponded: true,798 _neutralized: true799 };800 for12 = {801 _server: {},802 _feedOpenRequest: {803 clientId: "cid1",804 feedName: "feed2",805 feedArgs: { feed: "args2" }806 },807 _appResponded: true,808 _neutralized: false809 };810 for21 = {811 _server: {},812 _feedOpenRequest: {813 clientId: "cid2",814 feedName: "feed1",815 feedArgs: { feed: "args1" }816 },817 _appResponded: false,818 _neutralized: true819 };820 harn.server._feedOpenResponses = {821 cid1: { ser1: for11, ser2: for12 },822 cid2: { ser1: for21 }823 };824 });825 it("should represent the state correctly", () => {826 const state = harn.getServerState();827 expect(_.keys(state._feedOpenResponses).sort()).toEqual([828 "cid1",829 "cid2"830 ]);831 expect(_.keys(state._feedOpenResponses.cid1).sort()).toEqual([832 "ser1",833 "ser2"834 ]);835 expect(_.keys(state._feedOpenResponses.cid2).sort()).toEqual(["ser1"]);836 expect(state._feedOpenResponses.cid1.ser1).toBe(for11);837 expect(state._feedOpenResponses.cid1.ser2).toBe(for12);838 expect(state._feedOpenResponses.cid2.ser1).toBe(for21);839 expect(_.keys(state._feedOpenResponseStates).sort()).toEqual([840 "cid1",841 "cid2"842 ]);843 expect(_.keys(state._feedOpenResponseStates.cid1).sort()).toEqual([844 "ser1",845 "ser2"846 ]);847 expect(_.keys(state._feedOpenResponseStates.cid2).sort()).toEqual([848 "ser1"849 ]);850 expect(state._feedOpenResponseStates.cid1.ser1._server).toBe(851 for11._server852 );853 expect(854 state._feedOpenResponseStates.cid1.ser1._feedOpenRequest855 ).toEqual({856 clientId: "cid1",857 feedName: "feed1",858 feedArgs: { feed: "args1" }859 });860 expect(state._feedOpenResponseStates.cid1.ser1._appResponded).toBe(861 true862 );863 expect(state._feedOpenResponseStates.cid1.ser1._neutralized).toBe(true);864 expect(state._feedOpenResponseStates.cid1.ser2._server).toBe(865 for12._server866 );867 expect(868 state._feedOpenResponseStates.cid1.ser2._feedOpenRequest869 ).toEqual({870 clientId: "cid1",871 feedName: "feed2",872 feedArgs: { feed: "args2" }873 });874 expect(state._feedOpenResponseStates.cid1.ser2._appResponded).toBe(875 true876 );877 expect(state._feedOpenResponseStates.cid1.ser2._neutralized).toBe(878 false879 );880 expect(state._feedOpenResponseStates.cid2.ser1._server).toBe(881 for21._server882 );883 expect(884 state._feedOpenResponseStates.cid2.ser1._feedOpenRequest885 ).toEqual({886 clientId: "cid2",887 feedName: "feed1",888 feedArgs: { feed: "args1" }889 });890 expect(state._feedOpenResponseStates.cid2.ser1._appResponded).toBe(891 false892 );893 expect(state._feedOpenResponseStates.cid2.ser1._neutralized).toBe(true);894 });895 it("should compare the state correctly - match", () => {896 const state = harn.getServerState();897 expect(harn.server).toHaveState(state);898 });899 it("should compare the state correctly - mismatched ._feedOpenResponses key", () => {900 const state = harn.getServerState();901 state._feedOpenResponses.junk = {};902 const result = harness.toHaveState(harn.server, state);903 expect(result.pass).toBe(false);904 expect(result.message()).toEqual(905 "expected ._feedOpenResponses keys to match, but they didn't"906 );907 });908 it("should compare the state correctly - mismatched ._feedOpenResponses[cid] key", () => {909 const state = harn.getServerState();910 state._feedOpenResponses.cid1.junk = {};911 const result = harness.toHaveState(harn.server, state);912 expect(result.pass).toBe(false);913 expect(result.message()).toEqual(914 "expected ._feedOpenResponses[cid] keys to match, but they didn't"915 );916 });917 it("should compare the state correctly - mismatched ._feedOpenResponses[cid] value", () => {918 const state = harn.getServerState();919 state._feedOpenResponses.cid1.ser1 = {};920 const result = harness.toHaveState(harn.server, state);921 expect(result.pass).toBe(false);922 expect(result.message()).toEqual(923 "expected ._feedOpenResponses[cid] values to match, but they didn't"924 );925 });926 it("should compare the state correctly - mismatched ._feedOpenResponseStates key", () => {927 const state = harn.getServerState();928 state._feedOpenResponseStates.junk = {};929 const result = harness.toHaveState(harn.server, state);930 expect(result.pass).toBe(false);931 expect(result.message()).toEqual(932 "expected ._feedOpenResponseStates keys to match, but they didn't"933 );934 });935 it("should compare the state correctly - mismatched ._feedOpenResponseStates[cid] key", () => {936 const state = harn.getServerState();937 state._feedOpenResponseStates.cid1.junk = {};938 const result = harness.toHaveState(harn.server, state);939 expect(result.pass).toBe(false);940 expect(result.message()).toEqual(941 "expected ._feedOpenResponseStates[cid] keys to match, but they didn't"942 );943 });944 it("should compare the state correctly - mismatched ._feedOpenResponseStates[cid][ser] key", () => {945 const state = harn.getServerState();946 state._feedOpenResponseStates.cid1.ser1.junk = 123;947 const result = harness.toHaveState(harn.server, state);948 expect(result.pass).toBe(false);949 expect(result.message()).toEqual(950 "expected ._feedOpenResponseStates[cid][ser] keys to be valid, but they weren't"951 );952 });953 it("should compare the state correctly - mismatched ._feedOpenResponseStates[cid][ser]._server", () => {954 const state = harn.getServerState();955 state._feedOpenResponseStates.cid1.ser1._server = {};956 const result = harness.toHaveState(harn.server, state);957 expect(result.pass).toBe(false);958 expect(result.message()).toEqual(959 "expected ._feedOpenResponseStates[cid][ser] values to match, but they didn't"960 );961 });962 it("should compare the state correctly - mismatched ._feedOpenResponseStates[cid][ser]._actionRequest", () => {963 const state = harn.getServerState();964 state._feedOpenResponseStates.cid1.ser1._feedOpenRequest = {965 clientId: "junk",966 feedName: "junk",967 feedArgs: { feed: "junk" }968 };969 const result = harness.toHaveState(harn.server, state);970 expect(result.pass).toBe(false);971 expect(result.message()).toEqual(972 "expected ._feedOpenResponseStates[cid][ser] values to match, but they didn't"973 );974 });975 it("should compare the state correctly - mismatched ._feedOpenResponseStates[cid][ser]._appResponded", () => {976 const state = harn.getServerState();977 state._feedOpenResponseStates.cid1.ser1._appResponded = false;978 const result = harness.toHaveState(harn.server, state);979 expect(result.pass).toBe(false);980 expect(result.message()).toEqual(981 "expected ._feedOpenResponseStates[cid][ser] values to match, but they didn't"982 );983 });984 it("should compare the state correctly - mismatched ._feedOpenResponseStates[cid][ser]._neutralized", () => {985 const state = harn.getServerState();986 state._feedOpenResponseStates.cid1.ser1._neutralized = false;987 const result = harness.toHaveState(harn.server, state);988 expect(result.pass).toBe(false);989 expect(result.message()).toEqual(990 "expected ._feedOpenResponseStates[cid][ser] values to match, but they didn't"991 );992 });993 });994 describe("should handle ._feedCloseResponses (and state) correctly", () => {995 let harn;996 let fcr11;997 let fcr12;998 let fcr21;999 beforeEach(() => {1000 harn = harness();1001 fcr11 = {1002 _server: {},1003 _feedCloseRequest: {1004 clientId: "cid1",1005 feedName: "feed1",1006 feedArgs: { feed: "args1" }1007 },1008 _appResponded: true,1009 _neutralized: true1010 };1011 fcr12 = {1012 _server: {},1013 _feedCloseRequest: {1014 clientId: "cid1",1015 feedName: "feed2",1016 feedArgs: { feed: "args2" }1017 },1018 _appResponded: true,1019 _neutralized: false1020 };1021 fcr21 = {1022 _server: {},1023 _feedCloseRequest: {1024 clientId: "cid2",1025 feedName: "feed1",1026 feedArgs: { feed: "args1" }1027 },1028 _appResponded: false,1029 _neutralized: true1030 };1031 harn.server._feedCloseResponses = {1032 cid1: { ser1: fcr11, ser2: fcr12 },1033 cid2: { ser1: fcr21 }1034 };1035 });1036 it("should represent the state correctly", () => {1037 const state = harn.getServerState();1038 expect(_.keys(state._feedCloseResponses).sort()).toEqual([1039 "cid1",1040 "cid2"1041 ]);1042 expect(_.keys(state._feedCloseResponses.cid1).sort()).toEqual([1043 "ser1",1044 "ser2"1045 ]);1046 expect(_.keys(state._feedCloseResponses.cid2).sort()).toEqual(["ser1"]);1047 expect(state._feedCloseResponses.cid1.ser1).toBe(fcr11);1048 expect(state._feedCloseResponses.cid1.ser2).toBe(fcr12);1049 expect(state._feedCloseResponses.cid2.ser1).toBe(fcr21);1050 expect(_.keys(state._feedCloseResponses).sort()).toEqual([1051 "cid1",1052 "cid2"1053 ]);1054 expect(_.keys(state._feedCloseResponses.cid1).sort()).toEqual([1055 "ser1",1056 "ser2"1057 ]);1058 expect(_.keys(state._feedCloseResponses.cid2).sort()).toEqual(["ser1"]);1059 expect(state._feedCloseResponses.cid1.ser1._server).toBe(fcr11._server);1060 expect(state._feedCloseResponses.cid1.ser1._feedCloseRequest).toEqual({1061 clientId: "cid1",1062 feedName: "feed1",1063 feedArgs: { feed: "args1" }1064 });1065 expect(state._feedCloseResponses.cid1.ser1._appResponded).toBe(true);1066 expect(state._feedCloseResponses.cid1.ser1._neutralized).toBe(true);1067 expect(state._feedCloseResponses.cid1.ser2._server).toBe(fcr12._server);1068 expect(state._feedCloseResponses.cid1.ser2._feedCloseRequest).toEqual({1069 clientId: "cid1",1070 feedName: "feed2",1071 feedArgs: { feed: "args2" }1072 });1073 expect(state._feedCloseResponses.cid1.ser2._appResponded).toBe(true);1074 expect(state._feedCloseResponses.cid1.ser2._neutralized).toBe(false);1075 expect(state._feedCloseResponses.cid2.ser1._server).toBe(fcr21._server);1076 expect(state._feedCloseResponses.cid2.ser1._feedCloseRequest).toEqual({1077 clientId: "cid2",1078 feedName: "feed1",1079 feedArgs: { feed: "args1" }1080 });1081 expect(state._feedCloseResponses.cid2.ser1._appResponded).toBe(false);1082 expect(state._feedCloseResponses.cid2.ser1._neutralized).toBe(true);1083 });1084 it("should compare the state correctly - match", () => {1085 const state = harn.getServerState();1086 expect(harn.server).toHaveState(state);1087 });1088 it("should compare the state correctly - mismatched ._feedCloseResponses key", () => {1089 const state = harn.getServerState();1090 state._feedCloseResponses.junk = {};1091 const result = harness.toHaveState(harn.server, state);1092 expect(result.pass).toBe(false);1093 expect(result.message()).toEqual(1094 "expected ._feedCloseResponses keys to match, but they didn't"1095 );1096 });1097 it("should compare the state correctly - mismatched ._feedCloseResponses[cid] key", () => {1098 const state = harn.getServerState();1099 state._feedCloseResponses.cid1.junk = {};1100 const result = harness.toHaveState(harn.server, state);1101 expect(result.pass).toBe(false);1102 expect(result.message()).toEqual(1103 "expected ._feedCloseResponses[cid] keys to match, but they didn't"1104 );1105 });1106 it("should compare the state correctly - mismatched ._feedCloseResponses[cid] value", () => {1107 const state = harn.getServerState();1108 state._feedCloseResponses.cid1.ser1 = {};1109 const result = harness.toHaveState(harn.server, state);1110 expect(result.pass).toBe(false);1111 expect(result.message()).toEqual(1112 "expected ._feedCloseResponses[cid] values to match, but they didn't"1113 );1114 });1115 it("should compare the state correctly - mismatched ._feedCloseResponseStates key", () => {1116 const state = harn.getServerState();1117 state._feedCloseResponseStates.junk = {};1118 const result = harness.toHaveState(harn.server, state);1119 expect(result.pass).toBe(false);1120 expect(result.message()).toEqual(1121 "expected ._feedCloseResponseStates keys to match, but they didn't"1122 );1123 });1124 it("should compare the state correctly - mismatched ._feedCloseResponseStates[cid] key", () => {1125 const state = harn.getServerState();1126 state._feedCloseResponseStates.cid1.junk = {};1127 const result = harness.toHaveState(harn.server, state);1128 expect(result.pass).toBe(false);1129 expect(result.message()).toEqual(1130 "expected ._feedCloseResponseStates[cid] keys to match, but they didn't"1131 );1132 });1133 it("should compare the state correctly - mismatched ._feedCloseResponseStates[cid][ser] key", () => {1134 const state = harn.getServerState();1135 state._feedCloseResponseStates.cid1.ser1.junk = 123;1136 const result = harness.toHaveState(harn.server, state);1137 expect(result.pass).toBe(false);1138 expect(result.message()).toEqual(1139 "expected ._feedCloseResponseStates[cid][ser] keys to be valid, but they weren't"1140 );1141 });1142 it("should compare the state correctly - mismatched ._feedCloseResponseStates[cid][ser]._server", () => {1143 const state = harn.getServerState();1144 state._feedCloseResponseStates.cid1.ser1._server = {};1145 const result = harness.toHaveState(harn.server, state);1146 expect(result.pass).toBe(false);1147 expect(result.message()).toEqual(1148 "expected ._feedCloseResponseStates[cid][ser] values to match, but they didn't"1149 );1150 });1151 it("should compare the state correctly - mismatched ._feedCloseResponseStates[cid][ser]._actionRequest", () => {1152 const state = harn.getServerState();1153 state._feedCloseResponseStates.cid1.ser1._feedCloseRequest = {1154 clientId: "junk",1155 feedName: "junk",1156 feedArgs: { feed: "junk" }1157 };1158 const result = harness.toHaveState(harn.server, state);1159 expect(result.pass).toBe(false);1160 expect(result.message()).toEqual(1161 "expected ._feedCloseResponseStates[cid][ser] values to match, but they didn't"1162 );1163 });1164 it("should compare the state correctly - mismatched ._feedCloseResponseStates[cid][ser]._appResponded", () => {1165 const state = harn.getServerState();1166 state._feedCloseResponseStates.cid1.ser1._appResponded = false;1167 const result = harness.toHaveState(harn.server, state);1168 expect(result.pass).toBe(false);1169 expect(result.message()).toEqual(1170 "expected ._feedCloseResponseStates[cid][ser] values to match, but they didn't"1171 );1172 });1173 it("should compare the state correctly - mismatched ._feedCloseResponseStates[cid][ser]._neutralized", () => {1174 const state = harn.getServerState();1175 state._feedCloseResponseStates.cid1.ser1._neutralized = false;1176 const result = harness.toHaveState(harn.server, state);1177 expect(result.pass).toBe(false);1178 expect(result.message()).toEqual(1179 "expected ._feedCloseResponseStates[cid][ser] values to match, but they didn't"1180 );1181 });1182 });1183 });...
gracefulShutdown.ts
Source:gracefulShutdown.ts
2import {getServerState} from "./main";3import {clearPID} from "./Backup/clearPID";4import {updateWorkerStatus} from "./updateWorkerStatus";5export function taskStarted() {6 getServerState().taskCounter++;7 //Logger.instance.write("taskStarted " + getServerState().taskCounter);8}9export function taskDone() {10 getServerState().taskCounter--;11 //Logger.instance.write("taskDone " + getServerState().taskCounter);12}13export function gracefulShutdown(code: number) {14 if (Logger.instance) {15 Logger.instance.write("Shutting down in progress...");16 }17 getServerState().shutdownRequested = true;18 if (getServerState().shutdownTimer !== undefined) {19 getServerState().shutdownTimer.stop();20 }21 if (getServerState().heartBeatTimer !== undefined) {22 getServerState().shutdownTimer.stop();23 }24 let timeoutFunction = () => {25 if (getServerState().taskCounter <= 0) {26 if (Logger.instance) {27 Logger.instance.write("Shutting down with code ", String(code));28 Logger.instance.close();29 }30 if (getServerState().socket !== undefined) {31 getServerState().socket.closeAll();32 }33 clearPID();34 if (getServerState().heartBeatHost !== undefined) {35 updateWorkerStatus(parseInt(getServerState().workerId), "DOWN").then((v) => {36 process.exit(code);37 });38 } else {39 process.exit(code);40 }41 } else {42 setTimeout(timeoutFunction, 100);43 }44 }45 setTimeout(timeoutFunction, 100);...
serverState.js
Source:serverState.js
...3const SERVER_STATE_UPDATE = 'SERVER_STATE_UPDATE';4export default {5 Query: {6 serverState: async () => {7 const state = await getServerState();8 return { state };9 },10 },11 Mutation: {12 setState: async (_parent, args) => {13 await setServerState(args.state);14 const state = await getServerState();15 return { state };16 },17 },18 Subscription: {19 serverStateUpdate: {20 subscribe: () => {21 return pubsub.asyncIterator(SERVER_STATE_UPDATE);22 },23 },24 },...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getServerState(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12wpt.getLocations(function(err, data) {13 if (err) {14 console.log('Error: ' + err);15 } else {16 console.log(data);17 }18});
Using AI Code Generation
1wpt.getServerState(function(err, data) {2 if (err) {3 console.log('Error: ' + err);4 } else {5 console.log(data);6 }7});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!