2
0

xplatInterval.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // test custom GetSystemTime caching on xplat
  6. if (WScript.Platform && WScript.Platform.OS != "win32") {
  7. function rand() {
  8. return parseInt(Math.random() * 1e2) + 50;
  9. }
  10. for (var j = 0; j < 1e2; j++) {
  11. var pre_time = Date.now(), now;
  12. for(var i = 0; i < 1e6; i++) {
  13. now = Date.now();
  14. var diff = now - pre_time
  15. // INTERVAL_FOR_TICK_BACKUP = 5
  16. // So, anything beyond 5ms is not subject to our testing here.
  17. if (diff < 0 && Math.abs(diff) <= 5)
  18. {
  19. throw new Error ("Timer interval has failed. diff < 0 -> " + diff);
  20. }
  21. pre_time = now;
  22. }
  23. // wait rand time until next trial
  24. for(var i = 0, to = rand(); i < to; i++) {
  25. now = Date.now();
  26. }
  27. // INTERVAL_FOR_TICK_BACKUP = 5
  28. // So, anything beyond 5ms is not subject to our testing here.
  29. if (now < pre_time && Math.abs(now - pre_time) <= 5)
  30. {
  31. throw new Error ("Timer interval has failed. now < pre_time");
  32. }
  33. }
  34. } // !win32
  35. print("PASS");