huge.es.tst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. huge.tst - Huge get file
  3. */
  4. const HTTP = tget('TM_HTTP') || "127.0.0.1:8080"
  5. const TIMEOUT = 10000
  6. const HUGE= "../web/huge.txt"
  7. var SIZE = 5 * 1024 * 1024 * 1024
  8. let http: Http = new Http
  9. if (tdepth() >= 5) {
  10. /*
  11. Create test file
  12. */
  13. if (!Path(HUGE).exists || Path(HUGE).size < SIZE) {
  14. App.log.write("\n [Generate] Huge 5GB test file \"" + HUGE + "\" ...")
  15. let data = new ByteArray
  16. for (i in 1024) {
  17. data.write("%05d 0123456789012345678901234567890123456789012345678", i)
  18. }
  19. let f = File(HUGE, "w")
  20. while (Path(HUGE).size < SIZE) {
  21. f.write(data)
  22. }
  23. f.close()
  24. App.log.write("\n [Test] GET \"" + HUGE + "\" ...")
  25. }
  26. SIZE = Path(HUGE).size
  27. /*
  28. Test Http get for a huge file
  29. */
  30. let total, count, complete
  31. http.async = true
  32. http.setLimits({receive: 10 * 1024 * 1024 * 1024})
  33. var buf = new ByteArray
  34. http.on("readable", function (event, http) {
  35. buf.flush()
  36. count = http.read(buf, -1)
  37. total += count
  38. // printf("Read %d total %5.2f %%\n", count, total / SIZE * 100.0)
  39. })
  40. http.on("close", function (event, http) {
  41. complete = true
  42. })
  43. http.get(HTTP + "/huge.txt")
  44. let mark = new Date
  45. http.wait(-1)
  46. ttrue(complete)
  47. ttrue(total == SIZE)
  48. ttrue(http.status == 200)
  49. http.close()
  50. /*
  51. // Get first 5 bytes
  52. http.setHeader("Range", "bytes=0-4")
  53. http.get(HTTP + "/big.txt")
  54. ttrue(http.status == 206)
  55. ttrue(http.response == "01234")
  56. http.close()
  57. // Get last 5 bytes
  58. http.setHeader("Range", "bytes=-5")
  59. http.get(HTTP + "/big.txt")
  60. ttrue(http.status == 206)
  61. ttrue(http.response.trim() == "MENT")
  62. http.close()
  63. // Get from specific position till the end
  64. http.setHeader("Range", "bytes=117000-")
  65. http.get(HTTP + "/big.txt")
  66. ttrue(http.status == 206)
  67. ttrue(http.response.trim() == "END OF DOCUMENT")
  68. http.close()
  69. // Multiple ranges
  70. http.setHeader("Range", "bytes=0-5,25-30,-5")
  71. http.get(HTTP + "/big.txt")
  72. ttrue(http.status == 206)
  73. ttrue(http.response.contains("Content-Range: bytes 0-5/117016"))
  74. ttrue(http.response.contains("Content-Range: bytes 25-30/117016"))
  75. ttrue(http.response.contains("Content-Range: bytes 117011-117015/117016"))
  76. ttrue(http.response.contains("012345"))
  77. ttrue(http.response.contains("567890"))
  78. ttrue(http.response.contains("MENT"))
  79. http.close()
  80. */
  81. } else {
  82. tskip("Runs at depth 6")
  83. }