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

Fix random test failures on Mac #4

Merged
merged 1 commit into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ updates:
- dependency-name: dependency-check
- dependency-name: nyc
- dependency-name: standard
# ESM-only
- dependency-name: tempy
- package-ecosystem: github-actions
directory: /
schedule:
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node: [12, 14, 16]
name: Node ${{ matrix.node }}
os: [ubuntu-latest, macos-latest, windows-latest]
node: [12, 14, 16, 18]
name: Node ${{ matrix.node }} on ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"nyc": "^15.1.0",
"standard": "^16.0.3",
"tape": "^5.0.1",
"tempy": "^1.0.1",
"ts-standard": "^11.0.0",
"typescript": "^4.5.5"
},
Expand Down
2 changes: 1 addition & 1 deletion test/basic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const test = require('tape')
const tempy = require('tempy')
const tempy = require('./util/tempy')
const path = require('path')
const events = require('events')
const { RaveLevel } = require('..')
Expand Down
2 changes: 1 addition & 1 deletion test/bytewise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const test = require('tape')
const bytewise = require('bytewise')
const tempy = require('tempy')
const tempy = require('./util/tempy')
const { RaveLevel } = require('..')

test('bytewise key encoding', function (t) {
Expand Down
2 changes: 1 addition & 1 deletion test/election.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const test = require('tape')
const { once } = require('events')
const tempy = require('tempy')
const tempy = require('./util/tempy')
const { RaveLevel } = require('..')

test('basic failover', async function (t) {
Expand Down
39 changes: 21 additions & 18 deletions test/multi-process.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const test = require('tape')
const tempy = require('tempy')
const tempy = require('./util/tempy')
const { once } = require('events')
const { fork } = require('child_process')
const { RaveLevel } = require('..')
Expand All @@ -14,24 +14,27 @@ if (process.argv[2] === 'child') {
if (err) throw err
})
} else {
test('multiple processes', async function (t) {
const location = tempy.directory()
const entries = []
const promises = []
const exits = []
// Repeat because we have/had random issues here
for (let i = 0; i < 20; i++) {
test(`multiple processes (${i})`, async function (t) {
const location = tempy.directory()
const entries = []
const promises = []
const exits = []

for (let i = 0; i < 10; i++) {
const key = String(i).padStart(5, '0')
const value = String(Math.random())
const argv = ['child', location, key, value]
const child = fork(__filename, argv, { timeout: 30e3 })
for (let i = 0; i < 10; i++) {
const key = String(i).padStart(5, '0')
const value = String(Math.random())
const argv = ['child', location, key, value]
const child = fork(__filename, argv, { timeout: 30e3 })

entries.push([key, value])
promises.push(once(child, 'exit'))
exits.push([0, null])
}
entries.push([key, value])
promises.push(once(child, 'exit'))
exits.push([0, null])
}

t.same(await Promise.all(promises), exits)
t.same(await new RaveLevel(location).iterator().all(), entries)
})
t.same(await Promise.all(promises), exits)
t.same(await new RaveLevel(location).iterator().all(), entries)
})
}
}
2 changes: 1 addition & 1 deletion test/open-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const test = require('tape')
const { once } = require('events')
const tempy = require('tempy')
const tempy = require('./util/tempy')
const { RaveLevel } = require('..')

test('self-flush', async function (t) {
Expand Down
2 changes: 1 addition & 1 deletion test/sublevel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const test = require('tape')
const tempy = require('tempy')
const tempy = require('./util/tempy')
const { RaveLevel } = require('..')

test('sublevel', function (t) {
Expand Down
16 changes: 16 additions & 0 deletions test/util/tempy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

const path = require('path')
const crypto = require('crypto')
const fs = require('fs')
vweevers marked this conversation as resolved.
Show resolved Hide resolved
const tmp = require('os').tmpdir()

// We previously used https://www.npmjs.com/package/tempy but it
// returns directories that are too long. On Mac, the maximum length
// of a unix domain socket is 104 bytes. Exceeding that can result
// in EADDRINUSE errors.
exports.directory = function () {
const dir = path.join(tmp, crypto.randomBytes(10).toString('hex'))
fs.mkdirSync(dir)
return dir
}