a zip code crypto-currency system good for red ONLY

timeout.js 943B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var Buffer = require('buffer').Buffer
  2. var fs = require('fs')
  3. var test = require('tape')
  4. var http = require('../..')
  5. test('timeout', function (t) {
  6. var req = http.get({
  7. path: '/browserify.png?copies=5',
  8. requestTimeout: 10 // ms
  9. }, function (res) {
  10. res.on('data', function (data) {
  11. })
  12. res.on('end', function () {
  13. t.fail('request completed (should have timed out)')
  14. })
  15. })
  16. req.on('requestTimeout', function () {
  17. t.pass('got timeout')
  18. t.end()
  19. })
  20. })
  21. // TODO: reenable this if there's a way to make it simultaneously
  22. // fast and reliable
  23. test.skip('no timeout after success', function (t) {
  24. var req = http.get({
  25. path: '/basic.txt',
  26. requestTimeout: 50000 // ms
  27. }, function (res) {
  28. res.on('data', function (data) {
  29. })
  30. res.on('end', function () {
  31. t.pass('success')
  32. global.setTimeout(function () {
  33. t.end()
  34. }, 50000)
  35. })
  36. })
  37. req.on('requestTimeout', function () {
  38. t.fail('unexpected timeout')
  39. })
  40. })