From e57e532d287fdc2516b03b4ce0d61dd4d043fac6 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Fri, 19 Mar 2021 21:43:00 -0400 Subject: [PATCH] test: relax Y2K38 check in test-fs-utimes-y2K38 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: https://github.com/nodejs/node/pull/37825 Refs: https://github.com/nodejs/node/pull/37707 Reviewed-By: Rich Trott Reviewed-By: James M Snell --- test/parallel/test-fs-utimes-y2K38.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-fs-utimes-y2K38.js b/test/parallel/test-fs-utimes-y2K38.js index 06c5060c65d2fc..9e42e90feb1fd6 100644 --- a/test/parallel/test-fs-utimes-y2K38.js +++ b/test/parallel/test-fs-utimes-y2K38.js @@ -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'); @@ -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:/); } }