From eebf06b16c86cd40402c8d5566e01ca140802b24 Mon Sep 17 00:00:00 2001 From: James Sumners Date: Mon, 25 Nov 2024 09:35:01 -0500 Subject: [PATCH] chore: Fixed flaky test on macOS (#2790) --- test/integration/core/fs.test.js | 37 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/test/integration/core/fs.test.js b/test/integration/core/fs.test.js index 4e62c52a33..aae59dac02 100644 --- a/test/integration/core/fs.test.js +++ b/test/integration/core/fs.test.js @@ -6,14 +6,15 @@ 'use strict' const test = require('node:test') +const path = require('node:path') +const fs = require('node:fs') +const os = require('node:os') +const crypto = require('node:crypto') const { tspl } = require('@matteo.collina/tspl') -const path = require('path') -const fs = require('fs') -const os = require('os') + const helper = require('../../lib/agent_helper') const verifySegments = require('./verify') const NAMES = require('../../../lib/metrics/names') -const crypto = require('crypto') const isGlobSupported = require('semver').satisfies(process.version, '>=22.0.0') const tempDir = path.join(os.tmpdir(), crypto.randomUUID()) @@ -632,14 +633,22 @@ test('utimes', async function (t) { const name = path.join(tempDir, 'utimes-me') const content = 'some-content' fs.writeFileSync(name, content) - const accessed = new Date(5) - const modified = new Date(15) + const accessed = new Date('2024-11-25T08:00:00.000-05:00') + const modified = new Date('2024-11-25T08:01:00.000-05:00') + + t.after(async () => await fs.promises.unlink(name)) helper.runInTransaction(agent, function (trans) { fs.utimes(name, accessed, modified, function (err) { plan.ok(!err, 'should not error') const stats = fs.statSync(name) - plan.equal(stats.atime.toISOString(), accessed.toISOString()) + + if (process.platform !== 'darwin') { + plan.equal(stats.atime.toISOString(), accessed.toISOString()) + } else { + plan.ok('skipping access time check on macOS') + } + plan.equal(stats.mtime.toISOString(), modified.toISOString()) verifySegments({ agent, assert: plan, name: NAMES.FS.PREFIX + 'utimes' }) @@ -661,14 +670,22 @@ test('futimes', async function (t) { const content = 'some-content' fs.writeFileSync(name, content) const fd = fs.openSync(name, 'r+') - const accessed = new Date(5) - const modified = new Date(15) + const accessed = new Date('2024-11-25T08:00:00.000-05:00') + const modified = new Date('2024-11-25T08:01:00.000-05:00') + + t.after(async () => await fs.promises.unlink(name)) helper.runInTransaction(agent, function (trans) { fs.futimes(fd, accessed, modified, function (err) { plan.ok(!err, 'should not error') const stats = fs.statSync(name) - plan.equal(stats.atime.toISOString(), accessed.toISOString()) + + if (process.platform !== 'darwin') { + plan.equal(stats.atime.toISOString(), accessed.toISOString()) + } else { + plan.ok('skipping access time check on macOS') + } + plan.equal(stats.mtime.toISOString(), modified.toISOString()) verifySegments({ agent, assert: plan, name: NAMES.FS.PREFIX + 'futimes' })