upload.es.tst 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. upload.tst - Stress test uploads
  3. */
  4. const HTTP = tget('TM_HTTP') || '127.0.0.1:8080'
  5. const TESTFILE = 'upload-' + hashcode(App.pid) + '.tdat'
  6. /* This test requires chunking support */
  7. if (thas('ME_GOAHEAD_UPLOAD')) {
  8. let http: Http = new Http
  9. /* Depths: 0 1 2 3 4 5 6 7 8 9 */
  10. var sizes = [ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 ]
  11. // Create test data
  12. buf = new ByteArray
  13. for (i in 64) {
  14. for (j in 15) {
  15. buf.writeByte('A'.charCodeAt(0) + (j % 26))
  16. }
  17. buf.writeByte('\n'.charCodeAt(0))
  18. }
  19. // Create test data file
  20. f = File(TESTFILE).open({mode: 'w'})
  21. for (i in (sizes[tdepth()] * 1024)) {
  22. f.write(buf)
  23. }
  24. f.close()
  25. try {
  26. size = Path(TESTFILE).size
  27. http.upload(HTTP + '/action/uploadTest', { file: TESTFILE })
  28. ttrue(http.status == 200)
  29. http.close()
  30. let uploaded = Path('../web/tmp').join(Path(TESTFILE).basename)
  31. ttrue(uploaded.size == size)
  32. Cmd.sh('diff ' + uploaded + ' ' + TESTFILE)
  33. }
  34. finally {
  35. Path(TESTFILE).remove()
  36. }
  37. } else {
  38. tskip('Upload not enabled')
  39. }