Skip to content

Commit 7c27991

Browse files
authored
chore(bindings/nodejs): replace custom sleep with setTimeout in tests (#6563)
1 parent b018ba9 commit 7c27991

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

bindings/nodejs/tests/suites/asyncReadOptions.suite.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import { randomUUID } from 'node:crypto'
2121
import { test, describe, expect, assert } from 'vitest'
2222
import { Writable } from 'node:stream'
2323
import { finished, pipeline } from 'node:stream/promises'
24+
import { setTimeout } from 'node:timers/promises'
2425

25-
import { generateBytes, generateFixedBytes, sleep } from '../utils.mjs'
26+
import { generateBytes, generateFixedBytes } from '../utils.mjs'
2627

2728
/**
2829
* @param {import("../../index").Operator} op
@@ -108,7 +109,7 @@ export function run(op) {
108109
const bs = await op.read(filename, { ifModifiedSince: sinceMinus.toISOString() })
109110
assert.equal(Buffer.compare(bs, content), 0)
110111

111-
await sleep(1000)
112+
await setTimeout(1000)
112113

113114
const sinceAdd = new Date(meta.lastModified)
114115
sinceAdd.setSeconds(sinceAdd.getSeconds() + 1)
@@ -133,7 +134,7 @@ export function run(op) {
133134
'ConditionNotMatch',
134135
)
135136

136-
await sleep(1000)
137+
await setTimeout(1000)
137138

138139
const sinceAdd = new Date(meta.lastModified)
139140
sinceAdd.setSeconds(sinceAdd.getSeconds() + 1)
@@ -275,7 +276,7 @@ export function run(op) {
275276
const buf = Buffer.concat(chunks)
276277
assert.equal(Buffer.compare(buf, content), 0)
277278

278-
await sleep(1000)
279+
await setTimeout(1000)
279280

280281
const sinceAdd = new Date(meta.lastModified)
281282
sinceAdd.setSeconds(sinceAdd.getSeconds() + 1)
@@ -301,7 +302,7 @@ export function run(op) {
301302
const bs = Buffer.alloc(content.length)
302303
await expect(r.read(bs)).rejects.toThrowError('ConditionNotMatch')
303304

304-
await sleep(1000)
305+
await setTimeout(1000)
305306

306307
const sinceAdd = new Date(meta.lastModified)
307308
sinceAdd.setSeconds(sinceAdd.getSeconds() + 1)

bindings/nodejs/tests/suites/asyncStatOptions.suite.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
import { randomUUID } from 'node:crypto'
2121
import { test, describe, expect } from 'vitest'
22+
import { setTimeout } from 'node:timers/promises'
23+
2224
import { EntryMode } from '../../index.mjs'
23-
import { generateFixedBytes, sleep } from '../utils.mjs'
25+
import { generateFixedBytes } from '../utils.mjs'
2426

2527
/**
2628
* @param {import("../../index").Operator} op
@@ -90,7 +92,7 @@ export function run(op) {
9092
const metaMinus = await op.stat(filename, { ifModifiedSince: sinceMinus.toISOString() })
9193
expect(metaMinus.lastModified).toBe(meta.lastModified)
9294

93-
await sleep(1000)
95+
await setTimeout(1000)
9496

9597
const sinceAdd = new Date(meta.lastModified)
9698
sinceAdd.setSeconds(sinceAdd.getSeconds() + 1)
@@ -120,7 +122,7 @@ export function run(op) {
120122
'ConditionNotMatch',
121123
)
122124

123-
await sleep(1000)
125+
await setTimeout(1000)
124126

125127
const sinceAdd = new Date(meta.lastModified)
126128
sinceAdd.setSeconds(sinceAdd.getSeconds() + 1)

bindings/nodejs/tests/utils.mjs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,3 @@ export function loadConfigFromEnv(scheme) {
5353
.map(([key, value]) => [key.replace(prefix, ''), value]),
5454
)
5555
}
56-
57-
export function sleep(ms) {
58-
return new Promise((resolve) => setTimeout(resolve, ms))
59-
}

0 commit comments

Comments
 (0)