summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-06-19 02:58:49 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-06-14 03:24:41 +0800
commitb245257b70750bdc52a8c315de4b10965dacfed6 (patch)
tree004c92ceffe5f568ec5d06b592aaa38b157c80fe /test
parent4b1bcae681e209984604341f2acfe722345b1b23 (diff)
downloadandroid-node-v8-b245257b70750bdc52a8c315de4b10965dacfed6.tar.gz
android-node-v8-b245257b70750bdc52a8c315de4b10965dacfed6.tar.bz2
android-node-v8-b245257b70750bdc52a8c315de4b10965dacfed6.zip
fs: add *timeNs properties to BigInt Stats objects
- Extend the aliased buffer for stats objects to contain the entire time spec (seconds and nanoseconds) for the time values instead of calculating the milliseconds in C++ and lose precision there. - Calculate the nanosecond-precision time values in JS and expose them in BigInt Stats objects as `*timeNs`. The millisecond-precision values are now calculated from the nanosecond-precision values. PR-URL: https://github.com/nodejs/node/pull/21387 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-fs-stat-bigint.js20
-rw-r--r--test/parallel/test-fs-watchfile-bigint.js18
2 files changed, 33 insertions, 5 deletions
diff --git a/test/parallel/test-fs-stat-bigint.js b/test/parallel/test-fs-stat-bigint.js
index d004112680..998ddb289d 100644
--- a/test/parallel/test-fs-stat-bigint.js
+++ b/test/parallel/test-fs-stat-bigint.js
@@ -59,6 +59,26 @@ function verifyStats(bigintStats, numStats) {
bigintStats.isSymbolicLink(),
numStats.isSymbolicLink()
);
+ } else if (key.endsWith('Ms')) {
+ const nsKey = key.replace('Ms', 'Ns');
+ const msFromBigInt = bigintStats[key];
+ const nsFromBigInt = bigintStats[nsKey];
+ const msFromBigIntNs = Number(nsFromBigInt / (10n ** 6n));
+ const msFromNum = numStats[key];
+ // The difference between the millisecond-precision values should be
+ // smaller than 2
+ assert(
+ Math.abs(msFromNum - Number(msFromBigInt)) < 2,
+ `Number version ${key} = ${msFromNum}, ` +
+ `BigInt version ${key} = ${msFromBigInt}n`);
+ // The difference between the millisecond-precision value and the
+ // nanosecond-precision value scaled down to milliseconds should be
+ // smaller than 2
+ assert(
+ Math.abs(msFromNum - Number(msFromBigIntNs)) < 2,
+ `Number version ${key} = ${msFromNum}, ` +
+ `BigInt version ${nsKey} = ${nsFromBigInt}n` +
+ ` = ${msFromBigIntNs}ms`);
} else if (Number.isSafeInteger(val)) {
assert.strictEqual(
bigintStats[key], BigInt(val),
diff --git a/test/parallel/test-fs-watchfile-bigint.js b/test/parallel/test-fs-watchfile-bigint.js
index d5528bb2d3..500a0ef1f6 100644
--- a/test/parallel/test-fs-watchfile-bigint.js
+++ b/test/parallel/test-fs-watchfile-bigint.js
@@ -1,14 +1,18 @@
'use strict';
+
+// Flags: --expose-internals
+
const common = require('../common');
const assert = require('assert');
+const { BigIntStats } = require('internal/fs/utils');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const enoentFile = path.join(tmpdir.path, 'non-existent-file');
-const expectedStatObject = new fs.Stats(
+const expectedStatObject = new BigIntStats(
0n, // dev
0n, // mode
0n, // nlink
@@ -19,10 +23,14 @@ const expectedStatObject = new fs.Stats(
0n, // ino
0n, // size
0n, // blocks
- 0n, // atim_msec
- 0n, // mtim_msec
- 0n, // ctim_msec
- 0n // birthtim_msec
+ 0n, // atimeMs
+ 0n, // mtimeMs
+ 0n, // ctimeMs
+ 0n, // birthtimeMs
+ 0n, // atimeNs
+ 0n, // mtimeNs
+ 0n, // ctimeNs
+ 0n // birthtimeNs
);
tmpdir.refresh();