test-callback-without-filename.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2014, Krishna Raman <kraman@gmail.com>
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. var path = require('path');
  15. var http = require('http');
  16. var shelljs = require('shelljs');
  17. var test = require('tap').test;
  18. var heapdump = require('../');
  19. process.chdir(__dirname);
  20. function testFuncCall(test){
  21. var server = http.createServer(function(req, res) {
  22. res.writeHeader(200);
  23. res.end();
  24. });
  25. server.on('listening', function(){
  26. console.log('Listening on http://127.0.0.1:8000/');
  27. console.log('PID %d', process.pid);
  28. var heapSnapshotFile = 'heapdump-*.heapsnapshot';
  29. shelljs.rm('-f', heapSnapshotFile);
  30. function waitForHeapdump(err, filename) {
  31. var files = shelljs.ls(heapSnapshotFile);
  32. test.equals(err, null);
  33. test.equals(files.length, 1);
  34. test.equals(filename, files[0]);
  35. server.close();
  36. test.end();
  37. }
  38. heapdump.writeSnapshot(waitForHeapdump);
  39. });
  40. server.listen(0);
  41. }
  42. test('Test writeSnapshot and callback', testFuncCall);