Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jun 23, 2024
1 parent 72b2418 commit 491991e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 69 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"clean": "rimraf src/_lib src/tsconfig.build.tsbuildinfo",
"lint": "biome check . --apply",
"postinstall": "pnpm build",
"test": "vitest",
"test": "vitest --testTimeout 20000",
"test:cov": "vitest --coverage",
"typecheck": "tsc --noEmit"
},
Expand Down
32 changes: 14 additions & 18 deletions src/instances/silius.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,24 @@ test('behavior: instance errored (duplicate ports)', async () => {
await expect(() => instance_2.start()).rejects.toThrowError()
})

test(
'behavior: start and stop multiple times',
async () => {
const instance = defineInstance()

await instance.start()
await instance.stop()
await instance.start()
await instance.stop()
await instance.start()
await instance.stop()
await instance.start()
await instance.stop()
},
{ timeout: 10_000 },
)
test('behavior: start and stop multiple times', async () => {
const instance = defineInstance()

await instance.start()
await instance.stop()
await instance.start()
await instance.stop()
await instance.start()
await instance.stop()
await instance.start()
await instance.stop()
})

test('behavior: can subscribe to stderr', async () => {
const messages: string[] = []

const instance_1 = defineInstance({ port: 1337 })
const instance_2 = defineInstance({ port: 1337 })
const instance_1 = defineInstance({ port: 1338 })
const instance_2 = defineInstance({ port: 1338 })

await instance_1.start()
instance_2.on('stderr', (message) => messages.push(message))
Expand Down
42 changes: 19 additions & 23 deletions src/pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,25 @@ describe.each([
expect(pool.size).toEqual(0)
})

test(
'restart',
async () => {
pool = definePool({
instance,
})

const instance_1 = await pool.start(1)
const instance_2 = await pool.start(2)
const instance_3 = await pool.start(3)

expect(instance_1.status).toBe('started')
expect(instance_2.status).toBe('started')
expect(instance_3.status).toBe('started')
expect(pool.size).toEqual(3)

const promise_1 = pool.restart(1)
expect(instance_1.status).toBe('restarting')
await promise_1
expect(instance_1.status).toBe('started')
},
{ timeout: 10_000 },
)
test('restart', async () => {
pool = definePool({
instance,
})

const instance_1 = await pool.start(1)
const instance_2 = await pool.start(2)
const instance_3 = await pool.start(3)

expect(instance_1.status).toBe('started')
expect(instance_2.status).toBe('started')
expect(instance_3.status).toBe('started')
expect(pool.size).toEqual(3)

const promise_1 = pool.restart(1)
expect(instance_1.status).toBe('restarting')
await promise_1
expect(instance_1.status).toBe('started')
})

test('start > stop > start', async () => {
pool = definePool({
Expand Down
50 changes: 23 additions & 27 deletions src/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,29 +479,27 @@ describe("instance: 'rundler'", () => {
})

describe("instance: 'silius'", () => {
test(
'request: /{id}',
async () => {
const server = createServer({
instance: silius(siliusOptions({ port })),
})

const stop = await server.start()
const { port: port_2 } = server.address()!
const response = await fetch(`http://localhost:${port_2}/1`, {
body: JSON.stringify({
method: 'eth_supportedEntryPoints',
params: [],
id: 0,
jsonrpc: '2.0',
}),
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
})
expect(response.status).toBe(200)
expect(await response.json()).toMatchInlineSnapshot(`
test('request: /{id}', async () => {
const server = createServer({
instance: silius(siliusOptions({ port })),
})

const stop = await server.start()
const { port: port_2 } = server.address()!
const response = await fetch(`http://localhost:${port_2}/1`, {
body: JSON.stringify({
method: 'eth_supportedEntryPoints',
params: [],
id: 0,
jsonrpc: '2.0',
}),
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
})
expect(response.status).toBe(200)
expect(await response.json()).toMatchInlineSnapshot(`
{
"id": 0,
"jsonrpc": "2.0",
Expand All @@ -511,10 +509,8 @@ describe("instance: 'silius'", () => {
}
`)

await stop()
},
{ timeout: 10_000 },
)
await stop()
})
})

test('404', async () => {
Expand Down

0 comments on commit 491991e

Please sign in to comment.