Skip to content

Commit 595de43

Browse files
authored
fix: make tests more stable (#38)
Ensure we use prefixes in our tests that align with byte boundaries otherwise implementing blockstores will decode the wrong prefix.
1 parent b4a2514 commit 595de43

File tree

13 files changed

+58
-52
lines changed

13 files changed

+58
-52
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ jobs:
2020
- packages/interface-store
2121
steps:
2222
- uses: actions/checkout@v2
23-
- name: Use Node.js 14.x
23+
- name: Use Node.js 16.x
2424
uses: actions/setup-node@v1
2525
with:
26-
node-version: 14.x
26+
node-version: 16.x
2727
- name: Install dependencies
2828
run: npm install
29-
- name: Build types
29+
- name: Build project
3030
run: npm run build
31-
- name: Typecheck ${{ matrix.project }}
32-
uses: gozala/[email protected]
33-
with:
34-
project: ${{ matrix.project }}
35-
- run: npx aegir build
36-
- run: npx aegir dep-check
31+
- name: Check deps
32+
run: npm run dep-check
3733
- uses: ipfs/aegir/actions/bundle-size@master
3834
name: size
3935
with:
@@ -42,54 +38,36 @@ jobs:
4238
test-node:
4339
strategy:
4440
matrix:
45-
node-version: [14.x, 16.x]
4641
os: [windows-latest, ubuntu-latest, macos-latest]
4742
project:
48-
- packages/interface-blockstore
49-
- packages/interface-blockstore-tests
5043
- packages/interface-datastore
51-
- packages/interface-datastore-tests
52-
- packages/interface-store
5344
needs: check
5445
runs-on: ${{ matrix.os }}
55-
strategy:
56-
matrix:
57-
os: [windows-latest, ubuntu-latest, macos-latest]
58-
node: ${{ matrix.node-version }}
59-
fail-fast: true
6046
steps:
6147
- uses: actions/checkout@v2
6248
- uses: actions/setup-node@v1
6349
with:
64-
node-version: ${{ matrix.node-version }}
50+
node-version: 16.x
6551
- run: npm install
66-
- run: npx aegir test -t node --cov --bail
52+
- run: npm run test -- -- -- -t node --cov --bail
6753
- uses: codecov/codecov-action@v1
6854
test-chrome:
6955
needs: check
7056
runs-on: ubuntu-latest
7157
steps:
7258
- uses: actions/checkout@v2
59+
- uses: actions/setup-node@v1
60+
with:
61+
node-version: 16.x
7362
- run: npm install
74-
- run: npx aegir test -t browser -t webworker --bail
63+
- run: npm run test -- -- -- -t browser -t webworker --bail
7564
test-firefox:
7665
needs: check
7766
runs-on: ubuntu-latest
7867
steps:
7968
- uses: actions/checkout@v2
69+
- uses: actions/setup-node@v1
70+
with:
71+
node-version: 16.x
8072
- run: npm install
81-
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
82-
test-electron-main:
83-
needs: check
84-
runs-on: ubuntu-latest
85-
steps:
86-
- uses: actions/checkout@v2
87-
- run: npm install
88-
- run: npx xvfb-maybe aegir test -t electron-main --bail
89-
test-electron-renderer:
90-
needs: check
91-
runs-on: ubuntu-latest
92-
steps:
93-
- uses: actions/checkout@v2
94-
- run: npm install
95-
- run: npx xvfb-maybe aegir test -t electron-renderer --bail
73+
- run: npm run test -- -- -- -t browser -t webworker --bail -- --browser firefox

.nyc_output/coverage-final.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"test": "lerna run test",
1010
"build": "lerna run build",
1111
"lint": "lerna run lint",
12-
"release": "lerna run build && lerna publish"
12+
"release": "lerna run build && lerna publish",
13+
"dep-check": "lerna run dep-check"
1314
},
1415
"homepage": "https://github.com/ipfs/js-ipfs-interfaces/tree/master#readme",
1516
"bugs": "https://github.com/ipfs/js-ipfs-interfaces/issues",

packages/interface-blockstore-tests/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"scripts": {
1313
"build": "aegir build",
1414
"lint": "aegir ts -p check && aegir lint",
15-
"test": "echo \"No tests configured\""
15+
"test": "echo \"No tests configured\"",
16+
"dep-check": "aegir dep-check"
1617
},
1718
"repository": {
1819
"type": "git",
@@ -31,7 +32,7 @@
3132
"homepage": "https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-blockstore-tests#readme",
3233
"dependencies": {
3334
"aegir": "^35.0.0",
34-
"interface-blockstore": "^0.2.1",
35+
"interface-blockstore": "^1.0.1",
3536
"it-all": "^1.0.2",
3637
"it-drain": "^1.0.1",
3738
"it-length": "^1.0.2",

packages/interface-blockstore-tests/src/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const drain = require('it-drain')
77
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
88
const { CID } = require('multiformats/cid')
99
const { sha256 } = require('multiformats/hashes/sha2')
10+
const { base32 } = require('multiformats/bases/base32')
1011
const raw = require('multiformats/codecs/raw')
1112
const length = require('it-length')
1213

@@ -286,9 +287,9 @@ module.exports = (test) => {
286287
})
287288

288289
it('many (1200)', async function () {
289-
this.timeout(20 * 1000)
290+
this.timeout(60 * 1000)
290291
const b = store.batch()
291-
const count = 10
292+
const count = 1200
292293

293294
/** @type {Record<string, number>} */
294295
const prefixes = {}
@@ -300,7 +301,20 @@ module.exports = (test) => {
300301

301302
b.put(key, value)
302303

303-
const prefix = key.toString().substr(0, 13)
304+
// find the shortest stringified key that aligns with a byte boundary
305+
const keyStr = key.toString()
306+
let prefix = ''
307+
308+
for (let j = keyStr.length - 1; j > 20; j--) {
309+
try {
310+
base32.decode(keyStr.substring(0, j))
311+
prefix = keyStr.substring(0, j)
312+
} catch (err) {
313+
if (err.message !== 'Unexpected end of data') {
314+
throw err
315+
}
316+
}
317+
}
304318

305319
prefixes[prefix] = (prefixes[prefix] || 0) + 1
306320
}

packages/interface-blockstore/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"scripts": {
88
"build": "aegir build",
99
"test": "echo \"No tests configured\"",
10-
"lint": "aegir ts -p check && aegir lint"
10+
"lint": "aegir ts -p check && aegir lint",
11+
"dep-check": "aegir dep-check"
1112
},
1213
"license": "(Apache-2.0 OR MIT)",
1314
"homepage": "https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-blockstore#readme",
@@ -18,7 +19,7 @@
1819
},
1920
"dependencies": {
2021
"err-code": "^3.0.1",
21-
"interface-store": "^0.1.1",
22+
"interface-store": "^1.0.1",
2223
"it-all": "^1.0.5",
2324
"it-drain": "^1.0.4",
2425
"it-filter": "^1.0.2",

packages/interface-blockstore/src/types.d.ts renamed to packages/interface-blockstore/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
import type {
22
Pair as StorePair,
33
Batch as StoreBatch,
44
QueryFilter as StoreQueryFilter,
@@ -10,7 +10,7 @@ import {
1010
Options as StoreOptions,
1111
Store
1212
} from 'interface-store'
13-
import {
13+
import type {
1414
CID
1515
} from 'multiformats'
1616

packages/interface-datastore-tests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"scripts": {
1313
"build": "aegir build",
1414
"lint": "aegir ts -p check && aegir lint",
15-
"test": "echo \"No tests configured\""
15+
"test": "echo \"No tests configured\"",
16+
"dep-check": "aegir dep-check"
1617
},
1718
"repository": {
1819
"type": "git",

packages/interface-datastore/.nyc_output/coverage-final.json

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.

packages/interface-datastore/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"build": "aegir build",
1414
"lint": "aegir ts -p check && aegir lint",
1515
"test": "aegir test",
16-
"coverage": "aegir test --cov"
16+
"coverage": "aegir test --cov",
17+
"dep-check": "aegir dep-check -i interface-datastore-tests"
1718
},
1819
"repository": {
1920
"type": "git",
@@ -37,7 +38,7 @@
3738
},
3839
"dependencies": {
3940
"err-code": "^3.0.1",
40-
"interface-store": "^0.1.1",
41+
"interface-store": "^1.0.1",
4142
"ipfs-utils": "^8.1.2",
4243
"it-all": "^1.0.2",
4344
"it-drain": "^1.0.1",

0 commit comments

Comments
 (0)