Skip to content

Commit

Permalink
Add --no-tmp-gc flag for testing (#239)
Browse files Browse the repository at this point in the history
* Add --no-tmp-gc flag

* Move teardown back to updates test

* Move no gc to a constant

* Remove newline separating NO_GC from other constants

* Remove unused variable
  • Loading branch information
jkcdarunday authored Jul 29, 2024
1 parent 05115fb commit 7774f71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
14 changes: 1 addition & 13 deletions test/04-updates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const seedOpts = (id, dir = harness) => ({ channel: `test-${id}`, name: `test-${
const stageOpts = (id, dir) => ({ ...seedOpts(id, dir), dryRun: false, bare: true, ignore: [] })
const releaseOpts = (id, key) => ({ channel: `test-${id}`, name: `test-${id}`, key })
const ts = () => new Date().toISOString().replace(/[:.]/g, '-')
const gc = async (dir) => { try { await fs.promises.rm(dir, { recursive: true }) } catch { /* ignore */ } }
const tmp = fs.realpathSync(os.tmpdir())

class Rig {
Expand All @@ -35,16 +34,14 @@ class Rig {
comment('bootstrapping tmp platform...')
const platformDir = path.join(tmp, 'tmp-pear')
this.platformDir = platformDir
await gc(platformDir)
await fs.promises.mkdir(platformDir, { recursive: true })
await Helper.bootstrap(key, platformDir)
comment('tmp platform bootstrapped')
const bootstrapped = new Helper({ platformDir: this.platformDir })
this.bootstrapped = bootstrapped
comment('connecting tmp sidecar...')
await bootstrapped.ready()
comment('tmp sidecar connected')
global.Pear.teardown(async () => gc(platformDir))
global.Pear.teardown(async () => Helper.gc(platformDir))
}

cleanup = async ({ comment }) => {
Expand Down Expand Up @@ -253,8 +250,6 @@ test('Pear.updates should notify Platform stage updates (different pear instance

t.comment('bootstrapping rcv platform...')
const platformDirRcv = path.join(tmp, 'tmp-pear-rcv')
await gc(platformDirRcv)
await fs.promises.mkdir(platformDirRcv, { recursive: true })
await Helper.bootstrap(key, platformDirRcv)
const prefs = 'preferences.json'
fs.writeFileSync(path.join(platformDirRcv, prefs), JSON.stringify({ trusted: [appKey] }))
Expand All @@ -269,7 +264,6 @@ test('Pear.updates should notify Platform stage updates (different pear instance
comment('rcv sidecar shutting down..')
await rcv.shutdown()
comment('rcv sidecar shutdown')
await gc(platformDirRcv)
})

comment('running app from rcv platform')
Expand Down Expand Up @@ -358,8 +352,6 @@ test('Pear.updates should notify Platform stage, Platform release updates (diffe

comment('bootstrapping rcv platform...')
const platformDirRcv = path.join(tmp, 'tmp-pear-rcv')
await gc(platformDirRcv)
await fs.promises.mkdir(platformDirRcv, { recursive: true })
await Helper.bootstrap(key, platformDirRcv)
const prefs = 'preferences.json'
fs.writeFileSync(path.join(platformDirRcv, prefs), JSON.stringify({ trusted: [appKey] }))
Expand Down Expand Up @@ -467,8 +459,6 @@ test('Pear.updates should notify App stage updates (different pear instances)',

comment('bootstrapping rcv platform...')
const platformDirRcv = path.join(tmp, 'tmp-pear-rcv')
await gc(platformDirRcv)
await fs.promises.mkdir(platformDirRcv, { recursive: true })
await Helper.bootstrap(key, platformDirRcv)
const prefs = 'preferences.json'
fs.writeFileSync(path.join(platformDirRcv, prefs), JSON.stringify({ trusted: [appKey] }))
Expand Down Expand Up @@ -559,8 +549,6 @@ test('Pear.updates should notify App stage, App release updates (different pear

comment('bootstrapping rcv platform...')
const platformDirRcv = path.join(tmp, 'tmp-pear-rcv')
await gc(platformDirRcv)
await fs.promises.mkdir(platformDirRcv, { recursive: true })
await Helper.bootstrap(key, platformDirRcv)
const prefs = 'preferences.json'
fs.writeFileSync(path.join(platformDirRcv, prefs), JSON.stringify({ trusted: [appKey] }))
Expand Down
10 changes: 10 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const HOST = platform + '-' + arch
const BY_ARCH = path.join('by-arch', HOST, 'bin', `pear-runtime${isWindows ? '.exe' : ''}`)
const PLATFORM_DIR = global.Pear.config.pearDir
const { pathname } = new URL(global.Pear.config.applink)
const NO_GC = global.Pear.config.args.includes('--no-tmp-gc')

class Helper extends IPC {
#expectSidecar = false
Expand Down Expand Up @@ -174,9 +175,18 @@ class Helper extends IPC {
}

static async bootstrap (key, dir) {
await Helper.gc(dir)
await fs.promises.mkdir(dir, { recursive: true })

await updaterBootstrap(key, dir)
}

static async gc (dir) {
if (NO_GC) return

await fs.promises.rm(dir, { recursive: true }).catch(() => {})
}

static Inspector = class extends ReadyResource {
#session = null

Expand Down

0 comments on commit 7774f71

Please sign in to comment.