Remove mutex that was needed by jest

This commit is contained in:
Daniel Lugo 2021-09-23 21:46:41 -04:00
parent c89f3645d8
commit 8a5235461d

View file

@ -16,10 +16,6 @@ if (!fs.existsSync('./test-radata')) {
fs.mkdirSync('./test-radata') fs.mkdirSync('./test-radata')
} }
// start with true, have first test doesn't check, else all other test start to
// run right away
let isBusy = true
const instance = Gun({ const instance = Gun({
axe: false, axe: false,
multicast: false, multicast: false,
@ -30,25 +26,6 @@ const user = instance.user()
const alias = words() const alias = words()
const pass = words() const pass = words()
const release = () => {
isBusy = false
}
/**
* @returns {Promise<void>}
*/
const whenReady = () =>
new Promise(res => {
setTimeout(() => {
if (isBusy) {
whenReady().then(res)
} else {
isBusy = true
res()
}
}, 1000)
})
/** /**
* @param {number} ms * @param {number} ms
*/ */
@ -60,7 +37,6 @@ describe('gun smith', () => {
}) })
it('puts a true and reads it with once()', done => { it('puts a true and reads it with once()', done => {
// await whenReady()
logger.info('puts a true and reads it with once()') logger.info('puts a true and reads it with once()')
const a = words() const a = words()
const b = words() const b = words()
@ -76,7 +52,6 @@ describe('gun smith', () => {
.once(val => { .once(val => {
expect(val).toBe(true) expect(val).toBe(true)
done() done()
release()
}) })
}) })
@ -84,7 +59,6 @@ describe('gun smith', () => {
const a = words() const a = words()
const b = words() const b = words()
whenReady().then(() => {
instance instance
.get(a) .get(a)
.get(b) .get(b)
@ -98,18 +72,15 @@ describe('gun smith', () => {
.once(val => { .once(val => {
expect(val).toBe(false) expect(val).toBe(false)
done() done()
release()
}) })
} }
}) })
}) })
})
it('puts numbers and reads them with once()', done => { it('puts numbers and reads them with once()', done => {
const a = words() const a = words()
const b = words() const b = words()
whenReady().then(() => {
instance instance
.get(a) .get(a)
.get(b) .get(b)
@ -121,8 +92,6 @@ describe('gun smith', () => {
.once(val => { .once(val => {
expect(val).toBe(5) expect(val).toBe(5)
done() done()
release()
})
}) })
}) })
@ -130,7 +99,6 @@ describe('gun smith', () => {
const a = words() const a = words()
const b = words() const b = words()
const sentence = words({ exactly: 50 }).join(' ') const sentence = words({ exactly: 50 }).join(' ')
whenReady().then(() => {
instance instance
.get(a) .get(a)
.get(b) .get(b)
@ -142,13 +110,10 @@ describe('gun smith', () => {
.once(val => { .once(val => {
expect(val).toBe(sentence) expect(val).toBe(sentence)
done() done()
release()
})
}) })
}) })
it('merges puts', async () => { it('merges puts', async () => {
await whenReady()
const a = { const a = {
a: 1 a: 1
} }
@ -168,12 +133,9 @@ describe('gun smith', () => {
throw new Error('Data not an object') throw new Error('Data not an object')
} }
expect(removeBuiltInGunProps(data)).toEqual(c) expect(removeBuiltInGunProps(data)).toEqual(c)
release()
}) })
it('writes primitive items into sets and correctly assigns the id to ._.get', done => { it('writes primitive items into sets and correctly assigns the id to ._.get', done => {
whenReady().then(() => {
const node = instance.get(words()).get(words()) const node = instance.get(words()).get(words())
const item = node.set('hello') const item = node.set('hello')
@ -182,15 +144,12 @@ describe('gun smith', () => {
[item._.get]: 'hello' [item._.get]: 'hello'
}) })
done() done()
release()
})
}) })
}) })
// TODO: find out why this test fucks up the previous one if it runs before // TODO: find out why this test fucks up the previous one if it runs before
// that one // that one
it('maps over a primitive set', done => { it('maps over a primitive set', done => {
whenReady().then(() => {
const node = instance.get(words()).get(words()) const node = instance.get(words()).get(words())
const items = words({ exactly: 50 }) const items = words({ exactly: 50 })
@ -205,14 +164,11 @@ describe('gun smith', () => {
checked++ checked++
if (checked === 50) { if (checked === 50) {
done() done()
release()
} }
}) })
}) })
})
it('maps over an object set', done => { it('maps over an object set', done => {
whenReady().then(() => {
const node = instance.get(words()).get(words()) const node = instance.get(words()).get(words())
const items = words({ exactly: 50 }).map(w => ({ const items = words({ exactly: 50 }).map(w => ({
@ -229,14 +185,11 @@ describe('gun smith', () => {
checked++ checked++
if (checked === 50) { if (checked === 50) {
done() done()
release()
} }
}) })
}) })
})
it('offs `on()`s', async () => { it('offs `on()`s', async () => {
await whenReady()
const node = instance.get(words()).get(words()) const node = instance.get(words()).get(words())
let called = false let called = false
@ -250,12 +203,9 @@ describe('gun smith', () => {
await node.pPut('return') await node.pPut('return')
await delay(500) await delay(500)
expect(called).toBe(false) expect(called).toBe(false)
release()
}) })
it('offs `map().on()`s', async () => { it('offs `map().on()`s', async () => {
await whenReady()
const node = instance.get(words()).get(words()) const node = instance.get(words()).get(words())
let called = false let called = false
@ -273,13 +223,9 @@ describe('gun smith', () => {
await delay(500) await delay(500)
expect(called).toBe(false) expect(called).toBe(false)
release()
}) })
it('provides an user node with create(), auth() and leave()', async () => { it('provides an user node with create(), auth() and leave()', async () => {
await whenReady()
const ack = await new Promise(res => user.create(alias, pass, res)) const ack = await new Promise(res => user.create(alias, pass, res))
expect(ack.err).toBeUndefined() expect(ack.err).toBeUndefined()
@ -298,13 +244,9 @@ describe('gun smith', () => {
expect(authAck.sea?.pub).toEqual(pub) expect(authAck.sea?.pub).toEqual(pub)
expect(user.is?.pub).toEqual(pub) expect(user.is?.pub).toEqual(pub)
user.leave() user.leave()
release()
}) })
it('reliably provides authentication information across re-forges', async () => { it('reliably provides authentication information across re-forges', async () => {
await whenReady()
/** @type {GunT.AuthAck} */ /** @type {GunT.AuthAck} */
const authAck = await new Promise(res => const authAck = await new Promise(res =>
user.auth(alias, pass, ack => res(ack)) user.auth(alias, pass, ack => res(ack))
@ -318,12 +260,9 @@ describe('gun smith', () => {
expect(user.is?.pub).toEqual(pub) expect(user.is?.pub).toEqual(pub)
user.leave() user.leave()
release()
}) })
it('provides thenables for values', async () => { it('provides thenables for values', async () => {
await whenReady()
const a = words() const a = words()
const b = words() const b = words()
const node = instance.get(a).get(b) const node = instance.get(a).get(b)
@ -345,13 +284,9 @@ describe('gun smith', () => {
.get(b) .get(b)
.then() .then()
expect(fetch).toEqual(value) expect(fetch).toEqual(value)
release()
}) })
it('provides an special thenable put()', async () => { it('provides an special thenable put()', async () => {
await whenReady()
const a = words() const a = words()
const b = words() const b = words()
const node = instance.get(a).get(b) const node = instance.get(a).get(b)
@ -362,12 +297,9 @@ describe('gun smith', () => {
const res = await node.then() const res = await node.then()
expect(res).toBe(value) expect(res).toBe(value)
release()
}) })
it('on()s and handles object>primitive>object transitions', done => { it('on()s and handles object>primitive>object transitions', done => {
whenReady().then(() => {
const a = { const a = {
one: 1 one: 1
} }
@ -390,7 +322,6 @@ describe('gun smith', () => {
} else if (checked === 3) { } else if (checked === 3) {
expect(removeBuiltInGunProps(data)).toEqual(c) expect(removeBuiltInGunProps(data)).toEqual(c)
done() done()
release()
} }
}) })
@ -402,14 +333,12 @@ describe('gun smith', () => {
node.put(c) node.put(c)
}, 800) }, 800)
}) })
})
// ************************************************************************** // **************************************************************************
// ** Long tests below // ** Long tests below
// ************************************************************************** // **************************************************************************
it('writes object items into sets and correctly populates item._.get with the newly created id', done => { it('writes object items into sets and correctly populates item._.get with the newly created id', done => {
whenReady().then(() => {
const node = instance.get(words()).get(words()) const node = instance.get(words()).get(words())
const obj = { const obj = {
@ -422,13 +351,10 @@ describe('gun smith', () => {
node.get(item._.get).once(data => { node.get(item._.get).once(data => {
expect(removeBuiltInGunProps(data)).toEqual(obj) expect(removeBuiltInGunProps(data)).toEqual(obj)
done() done()
release()
})
}) })
}) })
it('provides an special once() that restarts gun until a value is fetched', done => { it('provides an special once() that restarts gun until a value is fetched', done => {
whenReady().then(() => {
const a = words() const a = words()
const b = words() const b = words()
const node = instance.get(a).get(b) const node = instance.get(a).get(b)
@ -437,18 +363,14 @@ describe('gun smith', () => {
node.specialOnce(data => { node.specialOnce(data => {
expect(data).toEqual(value) expect(data).toEqual(value)
done() done()
release()
}) })
setTimeout(() => { setTimeout(() => {
node.put(value) node.put(value)
}, 30000) }, 30000)
}) })
})
it('provides an special then() that restarts gun until a value is fetched', async () => { it('provides an special then() that restarts gun until a value is fetched', async () => {
await whenReady()
const a = words() const a = words()
const b = words() const b = words()
const node = instance.get(a).get(b) const node = instance.get(a).get(b)
@ -461,13 +383,10 @@ describe('gun smith', () => {
const res = await node.specialThen() const res = await node.specialThen()
expect(res).toBe(value) expect(res).toBe(value)
release()
}) })
it('provides an special on() that restarts gun when a value has not been obtained in a determinate amount of time', done => { it('provides an special on() that restarts gun when a value has not been obtained in a determinate amount of time', done => {
// Kinda crappy test, this should be easier to test in real usage. // Kinda crappy test, this should be easier to test in real usage.
whenReady().then(() => {
const initialProcCounter = Gun._getProcCounter() const initialProcCounter = Gun._getProcCounter()
const node = instance.get(words()).get(words()) const node = instance.get(words()).get(words())
@ -479,7 +398,6 @@ describe('gun smith', () => {
if (data === secondValue) { if (data === secondValue) {
expect(Gun._getProcCounter()).toEqual(initialProcCounter + 1) expect(Gun._getProcCounter()).toEqual(initialProcCounter + 1)
done() done()
release()
} }
}) })
) )
@ -489,4 +407,3 @@ describe('gun smith', () => {
}, 32000) }, 32000)
}) })
}) })
})