2018-01-21 19:21:25 +01:00
|
|
|
// Flags: --expose-gc --no-warnings --expose-internals
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2018-02-14 20:29:05 +01:00
|
|
|
const assert = require('assert');
|
2018-01-21 19:21:25 +01:00
|
|
|
const path = require('path');
|
|
|
|
const fs = process.binding('fs');
|
|
|
|
const { stringToFlags } = require('internal/fs');
|
|
|
|
|
|
|
|
// Verifies that the FileHandle object is garbage collected and that a
|
|
|
|
// warning is emitted if it is not closed.
|
|
|
|
|
|
|
|
let fdnum;
|
|
|
|
{
|
2018-02-14 20:29:05 +01:00
|
|
|
const ctx = {};
|
2018-01-21 19:21:25 +01:00
|
|
|
fdnum = fs.openFileHandle(path.toNamespacedPath(__filename),
|
2018-02-14 20:29:05 +01:00
|
|
|
stringToFlags('r'), 0o666, undefined, ctx).fd;
|
|
|
|
assert.strictEqual(ctx.errno, undefined);
|
2018-01-21 19:21:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
common.expectWarning(
|
|
|
|
'Warning',
|
2018-03-20 12:39:46 +01:00
|
|
|
`Closing file descriptor ${fdnum} on garbage collection`,
|
|
|
|
common.noWarnCode
|
2018-01-21 19:21:25 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
gc(); // eslint-disable-line no-undef
|
|
|
|
|
|
|
|
setTimeout(() => {}, 10);
|