2018-01-21 18:21:25 +00:00
|
|
|
// Flags: --expose-gc --no-warnings --expose-internals
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2018-02-14 19:29:05 +00:00
|
|
|
const assert = require('assert');
|
2018-01-21 18:21:25 +00:00
|
|
|
const path = require('path');
|
2018-08-23 14:29:40 +00:00
|
|
|
const { internalBinding } = require('internal/test/binding');
|
|
|
|
const fs = internalBinding('fs');
|
2018-05-03 18:40:48 +00:00
|
|
|
const { stringToFlags } = require('internal/fs/utils');
|
2018-01-21 18:21:25 +00:00
|
|
|
|
|
|
|
// Verifies that the FileHandle object is garbage collected and that a
|
|
|
|
// warning is emitted if it is not closed.
|
|
|
|
|
|
|
|
let fdnum;
|
|
|
|
{
|
2018-02-14 19:29:05 +00:00
|
|
|
const ctx = {};
|
2018-01-21 18:21:25 +00:00
|
|
|
fdnum = fs.openFileHandle(path.toNamespacedPath(__filename),
|
2018-02-14 19:29:05 +00:00
|
|
|
stringToFlags('r'), 0o666, undefined, ctx).fd;
|
|
|
|
assert.strictEqual(ctx.errno, undefined);
|
2018-01-21 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 14:29:40 +00:00
|
|
|
common.expectWarning({
|
|
|
|
'internal/test/binding': [
|
2018-12-28 13:33:33 +00:00
|
|
|
'These APIs are for internal testing only. Do not use them.'
|
2018-08-23 14:29:40 +00:00
|
|
|
],
|
|
|
|
'Warning': [
|
2018-12-28 13:33:33 +00:00
|
|
|
`Closing file descriptor ${fdnum} on garbage collection`
|
2018-08-23 14:29:40 +00:00
|
|
|
]
|
|
|
|
});
|
2018-01-21 18:21:25 +00:00
|
|
|
|
2018-12-13 13:36:42 +00:00
|
|
|
global.gc();
|
2018-01-21 18:21:25 +00:00
|
|
|
|
|
|
|
setTimeout(() => {}, 10);
|