You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. var WebSocket = require('../');
  2. var currentTest = 1;
  3. var lastTest = -1;
  4. var testCount = null;
  5. process.on('uncaughtException', function(err) {
  6. console.log('Caught exception: ', err, err.stack);
  7. });
  8. process.on('SIGINT', function () {
  9. try {
  10. console.log('Updating reports and shutting down');
  11. var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
  12. ws.on('close', function() {
  13. process.exit();
  14. });
  15. }
  16. catch(e) {
  17. process.exit();
  18. }
  19. });
  20. function nextTest() {
  21. if (currentTest > testCount || (lastTest != -1 && currentTest > lastTest)) {
  22. console.log('Updating reports and shutting down');
  23. var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
  24. ws.on('close', function() {
  25. process.exit();
  26. });
  27. return;
  28. };
  29. console.log('Running test case ' + currentTest + '/' + testCount);
  30. var ws = new WebSocket('ws://localhost:9001/runCase?case=' + currentTest + '&agent=ws');
  31. ws.on('message', function(data, flags) {
  32. ws.send(flags.buffer, {binary: flags.binary === true, mask: true});
  33. });
  34. ws.on('close', function(data) {
  35. currentTest += 1;
  36. process.nextTick(nextTest);
  37. });
  38. ws.on('error', function(e) {});
  39. }
  40. var ws = new WebSocket('ws://localhost:9001/getCaseCount');
  41. ws.on('message', function(data, flags) {
  42. testCount = parseInt(data);
  43. });
  44. ws.on('close', function() {
  45. if (testCount > 0) {
  46. nextTest();
  47. }
  48. });