Skip to content

Commit

Permalink
wip: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Apr 24, 2024
1 parent c7c0606 commit 36ca342
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/__tests__/connection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function createConnection(): BasicAtem {
}

function getChild(conn: BasicAtem): AtemSocketChildMock {
return (conn as any).socket._socketProcess
return (conn as any).socket._socketProcess.wrappedChild
}

function runTest(name: string, filename: string): void {
Expand Down Expand Up @@ -114,8 +114,6 @@ function runTest(name: string, filename: string): void {

const state0 = state as AtemState

commands.length = 0

for (const cmd of commands) {
test(`${cmd.constructor.name}`, async () => {
const newState = cloneJson(state0)
Expand Down
1 change: 1 addition & 0 deletions src/lib/__tests__/socket-child.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function fakeConnect(child: AtemSocketChild): void {
const child2 = child as any
child2._connectionState = ConnectionState.Established
child2._address = '127.0.0.1'
child2._port = 9910
child2.startTimers()
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/atemSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DEFAULT_PORT } from '../atem'
import type { OutboundPacketInfo } from './atemSocketChild'
import { PacketBuilder } from './packetBuilder'
import * as Comlink from 'comlink'
import { SocketWorkerApi } from './atemSocketChild2'
import { SocketWorkerApi } from './atemSocketChildWrapper'
import { Worker } from 'worker_threads'
import nodeEndpoint from 'comlink/dist/umd/node-adapter'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AtemSocketChild, OutboundPacketInfo } from './atemSocketChild'

export class SocketWorkerApi {
private tempChild: AtemSocketChild | undefined
private wrappedChild: AtemSocketChild | undefined

public async init(
debugBuffers: boolean,
Expand All @@ -10,9 +10,9 @@ export class SocketWorkerApi {
onCommandsReceived: (payload: Buffer) => Promise<void>,
onPacketsAcknowledged: (ids: Array<{ packetId: number; trackingId: number }>) => Promise<void>
): Promise<void> {
if (this.tempChild) throw new Error('Already initialised!')
if (this.wrappedChild) throw new Error('Already initialised!')

this.tempChild = new AtemSocketChild(
this.wrappedChild = new AtemSocketChild(
{
debugBuffers,
},
Expand All @@ -24,20 +24,20 @@ export class SocketWorkerApi {
}

public async connect(address: string, port: number): Promise<void> {
if (!this.tempChild) throw new Error('Not initialised!')
if (!this.wrappedChild) throw new Error('Not initialised!')

await this.tempChild.connect(address, port)
await this.wrappedChild.connect(address, port)
}

public async disconnect(): Promise<void> {
if (!this.tempChild) throw new Error('Not initialised!')
if (!this.wrappedChild) throw new Error('Not initialised!')

await this.tempChild.disconnect()
await this.wrappedChild.disconnect()
}

public async sendPackets(packets: OutboundPacketInfo[]): Promise<void> {
if (!this.tempChild) throw new Error('Not initialised!')
if (!this.wrappedChild) throw new Error('Not initialised!')

this.tempChild.sendPackets(packets)
this.wrappedChild.sendPackets(packets)
}
}
2 changes: 1 addition & 1 deletion src/lib/socket-worker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parentPort } from 'worker_threads'
import * as comlink from 'comlink'
import nodeEndpoint from 'comlink/dist/umd/node-adapter'
import { SocketWorkerApi } from './atemSocketChild2'
import { SocketWorkerApi } from './atemSocketChildWrapper'

if (!parentPort) {
throw new Error('InvalidWorker')
Expand Down

0 comments on commit 36ca342

Please sign in to comment.