|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const strictEqual = require('assert').strictEqual; |
| 5 | + |
| 6 | +function makeAssert(message) { |
| 7 | + return function(actual, expected) { |
| 8 | + strictEqual(actual, expected, message); |
| 9 | + }; |
| 10 | +} |
| 11 | + |
| 12 | + |
| 13 | +// child_process |
| 14 | +{ |
| 15 | + const assert = makeAssert('isRefed() not working on process_wrap'); |
| 16 | + const spawn = require('child_process').spawn; |
| 17 | + const cmd = common.isWindows ? 'rundll32' : 'ls'; |
| 18 | + const cp = spawn(cmd); |
| 19 | + assert(Object.getPrototypeOf(cp._handle).hasOwnProperty('isRefed'), true); |
| 20 | + assert(cp._handle.isRefed(), true); |
| 21 | + cp.unref(); |
| 22 | + assert(cp._handle.isRefed(), false); |
| 23 | + cp.ref(); |
| 24 | + assert(cp._handle.isRefed(), true); |
| 25 | + cp.unref(); |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +// dgram |
| 30 | +{ |
| 31 | + const assert = makeAssert('isRefed() not working on udp_wrap'); |
| 32 | + const dgram = require('dgram'); |
| 33 | + |
| 34 | + const sock4 = dgram.createSocket('udp4'); |
| 35 | + assert(Object.getPrototypeOf(sock4._handle).hasOwnProperty('isRefed'), true); |
| 36 | + assert(sock4._handle.isRefed(), true); |
| 37 | + sock4.unref(); |
| 38 | + assert(sock4._handle.isRefed(), false); |
| 39 | + sock4.ref(); |
| 40 | + assert(sock4._handle.isRefed(), true); |
| 41 | + sock4.unref(); |
| 42 | + |
| 43 | + const sock6 = dgram.createSocket('udp6'); |
| 44 | + assert(Object.getPrototypeOf(sock6._handle).hasOwnProperty('isRefed'), true); |
| 45 | + assert(sock6._handle.isRefed(), true); |
| 46 | + sock6.unref(); |
| 47 | + assert(sock6._handle.isRefed(), false); |
| 48 | + sock6.ref(); |
| 49 | + assert(sock6._handle.isRefed(), true); |
| 50 | + sock6.unref(); |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +// pipe |
| 55 | +{ |
| 56 | + const assert = makeAssert('isRefed() not working on pipe_wrap'); |
| 57 | + const Pipe = process.binding('pipe_wrap').Pipe; |
| 58 | + const handle = new Pipe(); |
| 59 | + assert(Object.getPrototypeOf(handle).hasOwnProperty('isRefed'), true); |
| 60 | + assert(handle.isRefed(), true); |
| 61 | + handle.unref(); |
| 62 | + assert(handle.isRefed(), false); |
| 63 | + handle.ref(); |
| 64 | + assert(handle.isRefed(), true); |
| 65 | + handle.unref(); |
| 66 | +} |
| 67 | + |
| 68 | + |
| 69 | +// tcp |
| 70 | +{ |
| 71 | + const assert = makeAssert('isRefed() not working on tcp_wrap'); |
| 72 | + const net = require('net'); |
| 73 | + const server = net.createServer(() => {}).listen(common.PORT); |
| 74 | + assert(Object.getPrototypeOf(server._handle).hasOwnProperty('isRefed'), true); |
| 75 | + assert(server._handle.isRefed(), true); |
| 76 | + assert(server._unref, false); |
| 77 | + server.unref(); |
| 78 | + assert(server._handle.isRefed(), false); |
| 79 | + assert(server._unref, true); |
| 80 | + server.ref(); |
| 81 | + assert(server._handle.isRefed(), true); |
| 82 | + assert(server._unref, false); |
| 83 | + server.unref(); |
| 84 | +} |
| 85 | + |
| 86 | + |
| 87 | +// timers |
| 88 | +{ |
| 89 | + const assert = makeAssert('isRefed() not working on timer_wrap'); |
| 90 | + const timer = setTimeout(() => {}, 500); |
| 91 | + timer.unref(); |
| 92 | + assert(Object.getPrototypeOf(timer._handle).hasOwnProperty('isRefed'), true); |
| 93 | + assert(timer._handle.isRefed(), false); |
| 94 | + timer.ref(); |
| 95 | + assert(timer._handle.isRefed(), true); |
| 96 | + timer.unref(); |
| 97 | +} |
0 commit comments