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

Fix e2e test cases with v4 SDK #916

Merged
merged 26 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4a1fe51
fail test if error code is null
iAmmar7 Nov 15, 2023
953718a
increase timeout limit for pubsub e2e test
iAmmar7 Nov 15, 2023
0dd4712
unsub chat event
iAmmar7 Nov 15, 2023
77a1987
update node version in github actions
iAmmar7 Nov 15, 2023
f451383
debug enable for prompt tests
iAmmar7 Nov 15, 2023
9bd98a3
remove logs from the SDK
iAmmar7 Nov 15, 2023
62b5809
send digits once prompt starts
iAmmar7 Nov 15, 2023
40b9c3e
end the call when caller ends the prompt
iAmmar7 Nov 15, 2023
30afda4
fix action onStarted promise
iAmmar7 Nov 21, 2023
8c9ff35
update voice speech test with v4 interface
iAmmar7 Nov 21, 2023
751616a
enable logs for chat test
iAmmar7 Nov 21, 2023
a648d61
kill all node process before running tests
iAmmar7 Nov 21, 2023
cdc6ca5
run only realtime tests
iAmmar7 Nov 21, 2023
24351e4
debug the ci
iAmmar7 Nov 21, 2023
6a3babf
child.stderr.write remove
iAmmar7 Nov 21, 2023
2c5c5d3
remove process.stderr in voiceSpeechCollect
iAmmar7 Nov 21, 2023
a63c20f
enable all the tests
iAmmar7 Nov 21, 2023
6baacc2
categorize tests by action type
iAmmar7 Nov 21, 2023
6565988
voice collect speech test with continuous true and partial results false
iAmmar7 Nov 22, 2023
383d2ee
voice collect speech test with continuous true and partial results true
iAmmar7 Nov 22, 2023
1299a3b
more simplified collect speech tests
iAmmar7 Nov 22, 2023
fbec0cf
include changeset
iAmmar7 Nov 22, 2023
b15ca78
increase tap timeout and fix race conditions in voice.test.ts
iAmmar7 Nov 22, 2023
d3c22bd
increase tap timeout
iAmmar7 Nov 22, 2023
961ae71
update possible results for collect
iAmmar7 Nov 22, 2023
49e7d38
tap setTimeout update
iAmmar7 Nov 22, 2023
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
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
Loading