Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: relax Y2K38 check in test-fs-utimes-y2K38 #37825

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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