|
4 | 4 | const common = require('../../common');
|
5 | 5 | const binding = require(`./build/${common.buildType}/test_buffer`);
|
6 | 6 | const assert = require('assert');
|
| 7 | +const setImmediatePromise = require('util').promisify(setImmediate); |
7 | 8 |
|
8 |
| -assert.strictEqual(binding.newBuffer().toString(), binding.theText); |
9 |
| -assert.strictEqual(binding.newExternalBuffer().toString(), binding.theText); |
10 |
| -console.log('gc1'); |
11 |
| -global.gc(); |
12 |
| -assert.strictEqual(binding.getDeleterCallCount(), 1); |
13 |
| -assert.strictEqual(binding.copyBuffer().toString(), binding.theText); |
| 9 | +(async function() { |
| 10 | + assert.strictEqual(binding.newBuffer().toString(), binding.theText); |
| 11 | + assert.strictEqual(binding.newExternalBuffer().toString(), binding.theText); |
| 12 | + console.log('gc1'); |
| 13 | + global.gc(); |
| 14 | + assert.strictEqual(binding.getDeleterCallCount(), 0); |
| 15 | + await setImmediatePromise(); |
| 16 | + assert.strictEqual(binding.getDeleterCallCount(), 1); |
| 17 | + assert.strictEqual(binding.copyBuffer().toString(), binding.theText); |
14 | 18 |
|
15 |
| -let buffer = binding.staticBuffer(); |
16 |
| -assert.strictEqual(binding.bufferHasInstance(buffer), true); |
17 |
| -assert.strictEqual(binding.bufferInfo(buffer), true); |
18 |
| -buffer = null; |
19 |
| -global.gc(); |
20 |
| -console.log('gc2'); |
21 |
| -assert.strictEqual(binding.getDeleterCallCount(), 2); |
| 19 | + let buffer = binding.staticBuffer(); |
| 20 | + assert.strictEqual(binding.bufferHasInstance(buffer), true); |
| 21 | + assert.strictEqual(binding.bufferInfo(buffer), true); |
| 22 | + buffer = null; |
| 23 | + global.gc(); |
| 24 | + assert.strictEqual(binding.getDeleterCallCount(), 1); |
| 25 | + await setImmediatePromise(); |
| 26 | + console.log('gc2'); |
| 27 | + assert.strictEqual(binding.getDeleterCallCount(), 2); |
| 28 | +})().then(common.mustCall()); |
0 commit comments