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

teardown test #409

Closed
wants to merge 152 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
9e54d1c
smoke-test-worker
maidh91 Oct 30, 2024
8bba39f
pipeWrite
maidh91 Oct 30, 2024
ad08515
basic-worker
maidh91 Oct 30, 2024
6af015b
revert
maidh91 Oct 30, 2024
bbd7d5a
promiseToComplete
maidh91 Oct 30, 2024
044b9e2
module.exports
maidh91 Oct 30, 2024
4052838
pipeWrite
maidh91 Oct 30, 2024
45c0f63
clean
maidh91 Oct 30, 2024
9f10bb1
Update 01-smoke.test.js
maidh91 Oct 30, 2024
5530057
new test
maidh91 Oct 31, 2024
c510434
clean
maidh91 Oct 31, 2024
172484b
clean
maidh91 Oct 31, 2024
1db49cf
clean
maidh91 Oct 31, 2024
bec4b1b
clean
maidh91 Oct 31, 2024
d5875dd
clean
maidh91 Oct 31, 2024
cc2d36e
clean
maidh91 Oct 31, 2024
80c1c84
clean
maidh91 Oct 31, 2024
40c9ebc
lint
maidh91 Oct 31, 2024
a532404
WorkerHelper
maidh91 Oct 31, 2024
5005cf9
command
maidh91 Oct 31, 2024
1f7af9e
teardown
maidh91 Oct 31, 2024
55b434f
clean
maidh91 Oct 31, 2024
488e524
revert
maidh91 Oct 31, 2024
3f89952
Helper.Worker
maidh91 Oct 31, 2024
d294364
lint
maidh91 Oct 31, 2024
fba25f7
move
maidh91 Oct 31, 2024
b213623
clean
maidh91 Oct 31, 2024
10eb60e
helper
maidh91 Nov 1, 2024
dfee37f
encrypted-test
maidh91 Nov 1, 2024
81b1df9
clean
maidh91 Nov 1, 2024
569330f
rename
maidh91 Nov 1, 2024
24fcaba
clean
maidh91 Nov 1, 2024
7350e12
clean
maidh91 Nov 1, 2024
ff53275
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 1, 2024
c89e7cd
rename
maidh91 Nov 1, 2024
dc933e5
name
maidh91 Nov 1, 2024
210e7f8
clean
maidh91 Nov 1, 2024
79bcd82
ok
maidh91 Nov 1, 2024
73b6841
lint
maidh91 Nov 1, 2024
5fb5f59
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 1, 2024
bc46dee
opts
maidh91 Nov 1, 2024
42c14aa
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 1, 2024
de39cdf
encryptionKeyName
maidh91 Nov 1, 2024
1c49748
check
maidh91 Nov 1, 2024
dd0929e
error
maidh91 Nov 1, 2024
b768cb6
teardown-2
maidh91 Nov 1, 2024
a790c3c
check
maidh91 Nov 1, 2024
a431415
log
maidh91 Nov 1, 2024
783e7e8
await pipeWrite
maidh91 Nov 1, 2024
d9d653c
clean
maidh91 Nov 1, 2024
0a5daf6
remove log
maidh91 Nov 1, 2024
1cdb759
clean
maidh91 Nov 1, 2024
99d4fa6
clean
maidh91 Nov 1, 2024
af4c799
ok
maidh91 Nov 1, 2024
ff38de5
pass
maidh91 Nov 1, 2024
665cad7
teardown executed
maidh91 Nov 1, 2024
fe76d82
teardown during teardown
maidh91 Nov 1, 2024
1dcfedc
workerTeardownExitCode
maidh91 Nov 1, 2024
0866055
exitCode
maidh91 Nov 1, 2024
fb03502
todo
maidh91 Nov 1, 2024
aafb558
clean
maidh91 Nov 1, 2024
aa84cfd
clean
maidh91 Nov 1, 2024
1773322
ok
maidh91 Nov 1, 2024
36a47a6
smoke
maidh91 Nov 1, 2024
1358c66
ok
maidh91 Nov 1, 2024
2bc96aa
split test
maidh91 Nov 1, 2024
0bdfb9d
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 1, 2024
d284704
revert
maidh91 Nov 1, 2024
23e1218
clean
maidh91 Nov 1, 2024
47a9764
alike
maidh91 Nov 1, 2024
2890b63
clean
maidh91 Nov 1, 2024
53e9fe1
solo
maidh91 Nov 1, 2024
016d991
timeoutId
maidh91 Nov 1, 2024
4094423
build
maidh91 Nov 1, 2024
972df23
build
maidh91 Nov 1, 2024
66bd38b
build
maidh91 Nov 1, 2024
8a756ce
ref
maidh91 Nov 1, 2024
ea24e0a
clean
maidh91 Nov 1, 2024
08312e8
err handler
maidh91 Nov 1, 2024
fa412f9
log
maidh91 Nov 1, 2024
99fcd1a
fs
maidh91 Nov 1, 2024
788b8f4
clean
maidh91 Nov 1, 2024
3c32b8c
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 1, 2024
c91bb80
encrypted
maidh91 Nov 1, 2024
ec21b0e
dir
maidh91 Nov 1, 2024
1cda8fd
lint
maidh91 Nov 1, 2024
36b05b9
crypto
maidh91 Nov 1, 2024
18a1326
up
maidh91 Nov 1, 2024
692610a
throws
maidh91 Nov 1, 2024
ca3d599
clean
maidh91 Nov 1, 2024
63130f9
rename
maidh91 Nov 1, 2024
da85d61
parse
maidh91 Nov 1, 2024
861c4d8
unexpected closed
maidh91 Nov 1, 2024
2e95af0
pipe end
maidh91 Nov 1, 2024
5349484
clearTimeout
maidh91 Nov 1, 2024
f186cbf
unexpected ended
maidh91 Nov 1, 2024
f66c6e3
key
maidh91 Nov 1, 2024
ddd8add
ended
maidh91 Nov 1, 2024
8c4c96a
buffer
maidh91 Nov 1, 2024
d880b50
inline test
maidh91 Nov 1, 2024
3cbdf25
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 1, 2024
da1ffe0
clean
maidh91 Nov 1, 2024
2c3e378
encryptionKey
maidh91 Nov 1, 2024
d80871a
RUNTIME override
davidmarkclements Nov 1, 2024
e7f1342
hack worker run
maidh91 Nov 1, 2024
07ea24b
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 1, 2024
054028d
teardown
maidh91 Nov 1, 2024
86490d7
a b
maidh91 Nov 1, 2024
164faac
teardown
maidh91 Nov 1, 2024
869a15c
timeout 5s
maidh91 Nov 1, 2024
70c982c
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 1, 2024
112ed20
revert
maidh91 Nov 1, 2024
651d2b3
test 1 ok
maidh91 Nov 2, 2024
42900bc
exit code ok
maidh91 Nov 2, 2024
952eda3
test 2
maidh91 Nov 2, 2024
49aaa4b
todi
maidh91 Nov 2, 2024
fe2a5da
remove nested teardown
maidh91 Nov 2, 2024
8b89be3
disable test
maidh91 Nov 3, 2024
c1745d5
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 3, 2024
e8e8da7
enable test
maidh91 Nov 3, 2024
fc564f7
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 3, 2024
eaf1509
enable test
maidh91 Nov 3, 2024
4509475
lint
maidh91 Nov 3, 2024
6ef4ee4
enable all tests
maidh91 Nov 4, 2024
25f19a0
enable all tests
maidh91 Nov 4, 2024
b625d4d
sequential
maidh91 Nov 4, 2024
8817282
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 4, 2024
594d545
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 4, 2024
096cb0e
deploy close
maidh91 Nov 4, 2024
f69794d
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 4, 2024
30e5de9
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 4, 2024
b5923e8
todo
maidh91 Nov 4, 2024
a6190ef
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 4, 2024
b015031
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 4, 2024
7b0cdb6
disable update test
maidh91 Nov 5, 2024
da15876
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 5, 2024
50c6d08
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 5, 2024
3818ba4
delay
maidh91 Nov 5, 2024
a366c39
remove delay
maidh91 Nov 5, 2024
9dcf609
ignore isWindows
maidh91 Nov 5, 2024
ae9eb93
clean
maidh91 Nov 5, 2024
bd272ae
teardown 3 tests
maidh91 Nov 5, 2024
e06eeda
remove package-lock
maidh91 Nov 5, 2024
3804710
lint
maidh91 Nov 5, 2024
29f8d49
enable all tests
maidh91 Nov 5, 2024
75bfc30
Merge branch 'smoke-test-1' of https://github.com/holepunchto/pear in…
maidh91 Nov 5, 2024
8e960ff
Merge branch 'encrypted-test' of https://github.com/holepunchto/pear …
maidh91 Nov 5, 2024
df43699
teardown-2
maidh91 Nov 5, 2024
9609718
clean 1
maidh91 Nov 5, 2024
a87aa1e
clean 2
maidh91 Nov 5, 2024
0421ed2
runFn
maidh91 Nov 5, 2024
7e18bdf
revert
maidh91 Nov 5, 2024
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
11 changes: 7 additions & 4 deletions lib/worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
const { isElectronRenderer, isWindows, isBare } = require('which-runtime')
const fs = isBare ? require('bare-fs') : require('fs')
const teardown = isBare ? require('./teardown') : (fn) => fn()
const { spawn } = isBare ? require('bare-subprocess') : require('child_process')
const { command } = require('paparam')
const Pipe = isBare
Expand All @@ -16,6 +17,7 @@ class Worker {
#ref = null
#unref = null
#ipc = null
static RUNTIME = constants.RUNTIME
constructor ({ ref = noop, unref = noop, ipc = null } = {}) {
this.#ref = ref
this.#unref = unref
Expand All @@ -41,7 +43,7 @@ class Worker {
run (link, args = []) {
if (isElectronRenderer) return this.#ipc.workerRun(link, args)
args = [...this.#args(link), ...args]
const sp = spawn(constants.RUNTIME, args, {
const sp = spawn(this.constructor.RUNTIME, args, {
stdio: ['inherit', 'inherit', 'inherit', 'overlapped'],
windowsHide: true
})
Expand All @@ -67,11 +69,12 @@ class Worker {
return null
}
const pipe = new Pipe(fd)
pipe.on('end', () => pipe.end())
pipe.on('end', () => {
teardown(() => pipe.end(), Number.MAX_SAFE_INTEGER)
})
this.#pipe = pipe
pipe.once('close', () => {
// allow close event to propagate between processes before exiting:
setImmediate(() => program.exit())
teardown(() => program.exit(), Number.MAX_SAFE_INTEGER)
})
return pipe
}
Expand Down
3 changes: 2 additions & 1 deletion test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
corestores
node_modules
.DS_Store
.DS_Store
package-lock.json
178 changes: 124 additions & 54 deletions test/01-smoke.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,162 @@ const test = require('brittle')
const path = require('bare-path')
const hypercoreid = require('hypercore-id-encoding')
const Helper = require('./helper')
const harness = path.join(Helper.localDir, 'test', 'fixtures', 'harness')
const assets = path.join(Helper.localDir, 'test', 'fixtures', 'app-with-assets')
const versionsDir = path.join(Helper.localDir, 'test', 'fixtures', 'versions')
const dhtBootstrapDir = path.join(Helper.localDir, 'test', 'fixtures', 'dht-bootstrap')
const requireAssets = path.join(Helper.localDir, 'test', 'fixtures', 'require-assets')
const subDepRequireAssets = path.join(Helper.localDir, 'test', 'fixtures', 'sub-dep-require-assets')

test('smoke', async function ({ ok, is, plan, comment, teardown, timeout, end }) {
test('smoke', async function ({ ok, is, alike, plan, comment, teardown, timeout }) {
timeout(180000)
plan(6)
const stager = new Helper()
teardown(() => stager.close(), { order: Infinity })
await stager.ready()
const dir = harness
plan(10)

const testVersions = async () => {
const dir = versionsDir

const helper = new Helper()
teardown(() => helper.close(), { order: Infinity })
await helper.ready()

const id = Math.floor(Math.random() * 10000)

comment('staging')
const staging = helper.stage({ channel: `test-${id}`, name: `test-${id}`, dir, dryRun: false, bare: true })
teardown(() => Helper.teardownStream(staging))
const staged = await Helper.pick(staging, { tag: 'final' })
ok(staged.success, 'stage succeeded')

comment('seeding')
const seeding = helper.seed({ channel: `test-${id}`, name: `test-${id}`, dir, key: null, cmdArgs: [] })
teardown(() => Helper.teardownStream(seeding))
const until = await Helper.pick(seeding, [{ tag: 'key' }, { tag: 'announced' }])
const announced = await until.announced
ok(announced, 'seeding is announced')

const key = await until.key
ok(hypercoreid.isValid(key), 'app key is valid')

const link = `pear://${key}`
const run = await Helper.run({ link })

const result = await Helper.untilResult(run.pipe)
const versions = JSON.parse(result)
is(versions.app.key, key, 'app version matches staged key')

await Helper.untilClose(run.pipe)
ok(true, 'ended')
}

const testDhtBootstrap = async () => {
const dir = dhtBootstrapDir

const helper = new Helper()
teardown(() => helper.close(), { order: Infinity })
await helper.ready()

const id = Math.floor(Math.random() * 10000)

comment('staging')
const staging = helper.stage({ channel: `test-${id}`, name: `test-${id}`, dir, dryRun: false, bare: true })
teardown(() => Helper.teardownStream(staging))
const staged = await Helper.pick(staging, { tag: 'final' })
ok(staged.success, 'stage succeeded')

comment('seeding')
const seeding = helper.seed({ channel: `test-${id}`, name: `test-${id}`, dir, key: null, cmdArgs: [] })
teardown(() => Helper.teardownStream(seeding))
const until = await Helper.pick(seeding, [{ tag: 'key' }, { tag: 'announced' }])
const announced = await until.announced
ok(announced, 'seeding is announced')

const key = await until.key
ok(hypercoreid.isValid(key), 'app key is valid')

const link = `pear://${key}`
const run = await Helper.run({ link })

const result = await Helper.untilResult(run.pipe)
const dhtBootstrap = JSON.parse(result)
alike(dhtBootstrap, Pear.config.dht.bootstrap, 'dht bootstrap matches Pear.config.dht.bootstrap')

await Helper.untilClose(run.pipe)
ok(true, 'ended')
}

await Promise.all([testVersions(), testDhtBootstrap()])
})

test('app with assets', async function ({ ok, is, plan, comment, teardown, timeout }) {
timeout(180000)
plan(5)

const dir = requireAssets

const helper = new Helper()
teardown(() => helper.close(), { order: Infinity })
await helper.ready()

const id = Math.floor(Math.random() * 10000)

comment('staging')
const staging = stager.stage({ channel: `test-${id}`, name: `test-${id}`, dir, dryRun: false, bare: true })
const staging = helper.stage({ channel: `test-${id}`, name: `test-${id}`, dir, dryRun: false, bare: true })
teardown(() => Helper.teardownStream(staging))
const final = await Helper.pick(staging, { tag: 'final' })
ok(final.success, 'stage succeeded')
const staged = await Helper.pick(staging, { tag: 'final' })
ok(staged.success, 'stage succeeded')

comment('seeding')
const seeder = new Helper()
teardown(() => seeder.close(), { order: Infinity })
await seeder.ready()
const seeding = seeder.seed({ channel: `test-${id}`, name: `test-${id}`, dir, key: null, cmdArgs: [] })
const seeding = helper.seed({ channel: `test-${id}`, name: `test-${id}`, dir, key: null, cmdArgs: [] })
teardown(() => Helper.teardownStream(seeding))
const until = await Helper.pick(seeding, [{ tag: 'key' }, { tag: 'announced' }])

const key = await until.key
const announced = await until.announced

ok(hypercoreid.isValid(key), 'app key is valid')
ok(announced, 'seeding is announced')

comment('running')
const link = 'pear://' + key
const running = await Helper.open(link, { tags: ['exit'] })
const key = await until.key
ok(hypercoreid.isValid(key), 'app key is valid')

const { value } = await running.inspector.evaluate('Pear.versions()', { awaitPromise: true })
is(value?.app?.key, key, 'app version matches staged key')
const link = `pear://${key}`
const run = await Helper.run({ link })

const dhtBootstrap = await running.inspector.evaluate('Pear.config.dht.bootstrap')
is(JSON.stringify(dhtBootstrap.value), JSON.stringify(Pear.config.dht.bootstrap), 'dht bootstrap matches Pear.config.dth.bootstrap')
const result = await Helper.untilResult(run.pipe)
is(result.trim(), 'This is the content of the asset', 'Read asset from entrypoint')

await running.inspector.close()
const { code } = await running.until.exit
is(code, 0, 'exit code is 0')
await Helper.untilClose(run.pipe)
ok(true, 'ended')
})

test('app with assets', async function ({ is, plan, comment, teardown, timeout }) {
test('app with assets in sub dep', async function ({ ok, is, plan, comment, teardown, timeout }) {
timeout(180000)
plan(3)
const stager = new Helper()
teardown(() => stager.close(), { order: Infinity })
await stager.ready()
const dir = assets
plan(5)

const dir = subDepRequireAssets

const helper = new Helper()
teardown(() => helper.close(), { order: Infinity })
await helper.ready()

const id = Math.floor(Math.random() * 10000)

comment('staging')
const staging = stager.stage({ channel: `test-${id}`, name: `test-${id}`, dir, dryRun: false, bare: true })
const staging = helper.stage({ channel: `test-${id}`, name: `test-${id}`, dir, dryRun: false, bare: true })
teardown(() => Helper.teardownStream(staging))
await Helper.pick(staging, { tag: 'final' })
const staged = await Helper.pick(staging, { tag: 'final' })
ok(staged.success, 'stage succeeded')

comment('seeding')
const seeder = new Helper()
teardown(() => seeder.close(), { order: Infinity })
await seeder.ready()
const seeding = seeder.seed({ channel: `test-${id}`, name: `test-${id}`, dir, key: null, cmdArgs: [] })
const seeding = helper.seed({ channel: `test-${id}`, name: `test-${id}`, dir, key: null, cmdArgs: [] })
teardown(() => Helper.teardownStream(seeding))
const until = await Helper.pick(seeding, [{ tag: 'key' }, { tag: 'announced' }])
const announced = await until.announced
ok(announced, 'seeding is announced')

const key = await until.key
await until.announced

comment('running')
const link = 'pear://' + key
const running = await Helper.open(link, { tags: ['exit'] })
ok(hypercoreid.isValid(key), 'app key is valid')

const { value: fromIndex } = await running.inspector.evaluate('global.readAsset()', { awaitPromise: true })
is(fromIndex.trim(), 'This is the content of the asset', 'Read asset from entrypoint')
const link = `pear://${key}`
const run = await Helper.run({ link })

const { value: fromUtils } = await running.inspector.evaluate('global.readAssetFromUtils()', { awaitPromise: true })
is(fromUtils.trim(), 'This is the content of the asset', 'Read asset from lib')
const result = await Helper.untilResult(run.pipe)
is(result.trim(), 'This is the content of the asset', 'Read asset from entrypoint')

await running.inspector.evaluate('disableInspector()')
await running.inspector.close()
const { code } = await running.until.exit
is(code, 0, 'exit code is 0')
await Helper.untilClose(run.pipe)
ok(true, 'ended')
})
Loading
Loading