Skip to content

Commit

Permalink
Fix e2e test cases with v4 SDK (#910)
Browse files Browse the repository at this point in the history
* fail test if error code is null

* increase timeout limit for pubsub e2e test

* unsub chat event

* update node version in github actions

* debug enable for prompt tests

* remove logs from the SDK

* send digits once prompt starts

* end the call when caller ends the prompt

* fix action onStarted promise

* update voice speech test with v4 interface

* enable logs for chat test

* kill all node process before running tests

* run only realtime tests

* debug the ci

* child.stderr.write remove

* remove process.stderr in voiceSpeechCollect

* enable all the tests

* categorize tests by action type

* voice collect speech test with continuous true and partial results false

* voice collect speech test with continuous true and partial results true

* more simplified collect speech tests

* include changeset

* increase tap timeout and fix race conditions in voice.test.ts

* increase tap timeout

* update possible results for collect

* tap setTimeout update
  • Loading branch information
iAmmar7 committed Nov 23, 2023
1 parent 15334d8 commit db1dba2
Show file tree
Hide file tree
Showing 37 changed files with 1,044 additions and 299 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-tigers-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/realtime-api': patch
---

Fix `onStarted` function in decorated promises
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit and stack tests
name: Tests

on:
push:
Expand Down
39 changes: 25 additions & 14 deletions internal/e2e-realtime-api/src/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ const testSubscribe = ({ jsChat, rtChat }: TestChatOptions) => {
console.log('Running subscribe..')
let events = 0

const resolveIfDone = () => {
let unsubRTChannel: Promise<() => Promise<void>>

const resolveIfDone = async () => {
// wait 4 events (rt and js receive their own events + the other member)
if (events === 4) {
jsChat.off('member.joined')
await (
await unsubRTChannel
)()
resolve(0)
}
}
Expand All @@ -71,18 +76,17 @@ const testSubscribe = ({ jsChat, rtChat }: TestChatOptions) => {
resolveIfDone()
})

const [unsubRTClient] = await Promise.all([
rtChat.listen({
channels: [channel],
onMemberJoined(member) {
// TODO: Check the member payload
console.log('rtChat member.joined')
events += 1
resolveIfDone()
},
}),
jsChat.subscribe(channel),
])
unsubRTChannel = rtChat.listen({
channels: [channel],
onMemberJoined(member) {
// TODO: Check the member payload
console.log('rtChat member.joined')
events += 1
resolveIfDone()
},
})

await Promise.all([unsubRTChannel, jsChat.subscribe(channel)])
})

return timeoutPromise(promise, promiseTimeout, promiseException)
Expand Down Expand Up @@ -275,6 +279,7 @@ const testDisconnectedRTClient = (rtClient: RealtimeSWClient) => {

reject(4)
} catch (e) {
console.log('Client disconnected okay!')
resolve(0)
}
})
Expand All @@ -289,6 +294,9 @@ const handler = async () => {
host: process.env.RELAY_HOST,
// @ts-expect-error
token: CRT.token,
debug: {
logWsTraffic: true,
},
})

const jsChatResultCode = await testChatMethod(jsChat)
Expand All @@ -302,6 +310,9 @@ const handler = async () => {
host: process.env.RELAY_HOST,
project: process.env.RELAY_PROJECT as string,
token: process.env.RELAY_TOKEN as string,
// debug: {
// logWsTraffic: true,
// },
})
const rtChat = rtClient.chat

Expand Down Expand Up @@ -372,7 +383,7 @@ async function main() {
const runner = createTestRunner({
name: 'Chat E2E',
testHandler: handler,
executionTime: 15_000,
executionTime: 30_000,
})

await runner.run()
Expand Down
1 change: 1 addition & 0 deletions internal/e2e-realtime-api/src/pubSub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ async function main() {
const runner = createTestRunner({
name: 'PubSub E2E',
testHandler: handler,
executionTime: 20_000,
})

await runner.run()
Expand Down
9 changes: 2 additions & 7 deletions internal/e2e-realtime-api/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tap from 'tap'
import { request } from 'node:https'
import { randomUUID, randomBytes } from 'node:crypto'

Expand Down Expand Up @@ -43,7 +44,6 @@ interface CreateTestRunnerParams {
testHandler: TestHandler
executionTime?: number
useDomainApp?: boolean
exitOnSuccess?: boolean
}

export const createTestRunner = ({
Expand All @@ -52,7 +52,6 @@ export const createTestRunner = ({
testHandler,
executionTime = MAX_EXECUTION_TIME,
useDomainApp = false,
exitOnSuccess = true,
}: CreateTestRunnerParams) => {
let timer: ReturnType<typeof setTimeout>

Expand All @@ -61,15 +60,13 @@ export const createTestRunner = ({
console.error(`Test Runner ${name} ran out of time (${executionTime})`)
process.exit(2)
}, executionTime)
tap.setTimeout(executionTime)
}

const done = (exitCode: number) => {
clearTimeout(timer)
if (exitCode === 0) {
console.log(`Test Runner ${name} Passed!`)
if (!exitOnSuccess) {
return
}
} else {
console.log(`Test Runner ${name} finished with exitCode: ${exitCode}`)
}
Expand All @@ -94,7 +91,6 @@ export const createTestRunner = ({
if (params.domainApp) {
console.log('Delete domain app..')
await deleteDomainApp({ id: params.domainApp.id })
delete params.domainApp
}
done(exitCode)
} catch (error) {
Expand All @@ -103,7 +99,6 @@ export const createTestRunner = ({
if (params.domainApp) {
console.log('Delete domain app..')
await deleteDomainApp({ id: params.domainApp.id })
delete params.domainApp
}
done(1)
}
Expand Down
28 changes: 21 additions & 7 deletions internal/e2e-realtime-api/src/voice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const handler: TestHandler = ({ domainApp }) => {
let outboundCall: Voice.Call
let callsReceived = new Set()

let waitForDetectStartResolve: () => void
const waitForDetectStart = new Promise<void>((resolve) => {
waitForDetectStartResolve = resolve
})

const unsubVoice = await client.voice.listen({
topics: [domainApp.call_relay_context],
onCallReceived: async (call) => {
Expand Down Expand Up @@ -53,11 +58,14 @@ const handler: TestHandler = ({ domainApp }) => {
)

if (callsReceived.size === 2) {
// Wait until the outbound peer starts digit detection
await waitForDetectStart

const sendDigitResult = await call.sendDigits('1#')
tap.equal(
call.id,
sendDigitResult.id,
'Peer - SendDigit returns the same instance'
'PeerInboundCall - SendDigit returns the same instance'
)

return
Expand Down Expand Up @@ -177,16 +185,22 @@ const handler: TestHandler = ({ domainApp }) => {
console.log('Peer:', peer.id, peer.type, peer.from, peer.to)
console.log('Main:', call.id, call.type, call.from, call.to)

const detector = await call.detectDigit({
digits: '1',
})
const detector = await call
.detectDigit({
digits: '1',
})
.onStarted()

// Inform inbound peer that the detector has started
waitForDetectStartResolve()

const detected = await detector.ended()

// TODO: update this once the backend can send us the actual result
tap.equal(
// @ts-expect-error
detector.detect.params.event,
detected.detect?.params.event,
'finished',
'Peer - Detect digit is finished'
'PeerOutboundCall - Detect digit is finished'
)

console.log('Finishing the calls.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CALL_PROPS,
TestHandler,
makeSipDomainAppAddress,
} from './utils'
} from '../utils'

const handler: TestHandler = ({ domainApp }) => {
if (!domainApp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CALL_PROPS,
TestHandler,
makeSipDomainAppAddress,
} from './utils'
} from '../utils'

const handler: TestHandler = ({ domainApp }) => {
if (!domainApp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CALL_PROPS,
TestHandler,
makeSipDomainAppAddress,
} from './utils'
} from '../utils'

const handler: TestHandler = ({ domainApp }) => {
if (!domainApp) {
Expand Down
Loading

0 comments on commit db1dba2

Please sign in to comment.