Skip to content

Commit

Permalink
test: relax Y2K38 check in test-fs-utimes-y2K38
Browse files Browse the repository at this point in the history
On some platforms `date` may not support the `-r` option. Optimistically
allow the test to proceed in that case as the previous `touch` had
succeeded -- we were just not able to easily validate the file date.

PR-URL: #37825
Refs: #37707
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
richardlau authored and ruyadorno committed Mar 24, 2021
1 parent cdfc1c8 commit 44490af
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions test/parallel/test-fs-utimes-y2K38.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
'use strict';
const common = require('../common');

if (common.isIBMi) {
common.skip('fs.utimesSync() currently fails on IBM i with Y2K38 values');
}

const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const assert = require('assert');
const fs = require('fs');

// Check for Y2K38 support. For Windows and AIX, assume it's there. Windows
// Check for Y2K38 support. For Windows, assume it's there. Windows
// doesn't have `touch` and `date -r` which are used in the check for support.
// AIX lacks `date -r`.
if (!common.isWindows && !common.isAIX) {
if (!common.isWindows) {
const testFilePath = `${tmpdir.path}/y2k38-test`;
const testFileDate = '204001020304';
const { spawnSync } = require('child_process');
Expand All @@ -25,13 +20,21 @@ if (!common.isWindows && !common.isAIX) {
common.skip('File system appears to lack Y2K38 support (touch failed)');
}

// On some file systems that lack Y2K38 support, `touch` will succeed but
// the time will be incorrect.
const dateResult = spawnSync('date',
['-r', testFilePath, '+%Y%m%d%H%M'],
{ encoding: 'utf8' });

assert.strictEqual(dateResult.status, 0);
if (dateResult.stdout.trim() !== testFileDate) {
common.skip('File system appears to lack Y2k38 support (date failed)');
if (dateResult.status === 0) {
if (dateResult.stdout.trim() !== testFileDate) {
common.skip('File system appears to lack Y2k38 support (date failed)');
}
} else {
// On some platforms `date` may not support the `-r` option. Usually
// this will result in a non-zero status and usage information printed.
// In this case optimistically proceed -- the earlier `touch` succeeded
// but validation that the file has the correct time is not easily possible.
assert.match(dateResult.stderr, /[Uu]sage:/);
}
}

Expand Down

0 comments on commit 44490af

Please sign in to comment.