Skip to content

Commit

Permalink
chore: Trying to fix the pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
FranklinWaller committed Oct 2, 2023
1 parent cc6311e commit 4ef493a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
3 changes: 2 additions & 1 deletion libs/as-sdk-integration-tests/src/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { PromiseStatus } from '../../../dist/libs/vm/src/types/vm-promise';

const mockHttpFetch = jest.fn();

jest.setTimeout(30_000);

const TestVmAdapter = jest.fn().mockImplementation(() => {
return { httpFetch: mockHttpFetch };
});

describe('Http', () => {
it('Test SDK HTTP Rejection', async () => {

const wasmBinary = await readFile('dist/libs/as-sdk-integration-tests/debug.wasm');
const result = await callVm({
args: ['testHttpRejection'],
Expand Down
22 changes: 13 additions & 9 deletions libs/vm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ export function callVm(callData: VmCallData, workerUrl = DEFAULT_WORKER_PATH, vm
type: WorkerMessageType.VmCall,
};

worker.on('message', (message: WorkerMessage) => {
if (message.type === WorkerMessageType.VmResult) {
resolve(message.result);
} else if (message.type === WorkerMessageType.VmActionExecute) {
hostToWorker.executeAction(message.action);
} else if (message.type === WorkerMessageType.VmActionResultBuffer) {
hostToWorker.sendActionResultToWorker(message.buffer);
} else {
console.warn('Unknown message', message);
worker.on('message', async (message: WorkerMessage) => {
try {
if (message.type === WorkerMessageType.VmResult) {
resolve(message.result);
} else if (message.type === WorkerMessageType.VmActionExecute) {
await hostToWorker.executeAction(message.action);
} else if (message.type === WorkerMessageType.VmActionResultBuffer) {
await hostToWorker.sendActionResultToWorker(message.buffer);
} else {
console.warn('Unknown message', message);
}
} catch (error) {
console.error('@callVm-onMessage: ', error);
}
});

Expand Down
4 changes: 4 additions & 0 deletions libs/vm/src/vm-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ export default class VmImports {
}

httpFetch(action: number, actionLength: number) {
console.log("HTTP Action called");
const rawAction = new Uint8Array(
this.memory?.buffer.slice(action, action + actionLength) ?? []
);
const messageRaw = Buffer.from(rawAction).toString('utf-8');

console.log('HTTP Action called with ', messageRaw);

try {
const message: HttpFetchAction = JSON.parse(messageRaw);
this.callResult = this.workerToHost.callActionOnHost(message);
console.log('We got a result: ', this.callResult);
return this.callResult.length;
} catch (error) {
console.error(`@httpFetch: ${messageRaw}`, error);
Expand Down
2 changes: 2 additions & 0 deletions libs/vm/src/vm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { PromiseStatus } from "../../../dist/libs/vm/src/types/vm-promise";

const mockHttpFetch = jest.fn();

jest.setTimeout(10_000);

const TestVmAdapter = jest.fn().mockImplementation(() => {
return { httpFetch: mockHttpFetch };
});
Expand Down
3 changes: 3 additions & 0 deletions libs/vm/src/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export async function executeVm(callData: VmCallData, notifierBuffer: SharedArra
const memory = instance.exports.memory;
vmImports.setMemory(memory as WebAssembly.Memory);

console.log("Starting WASI");
const exitCode = wasi.start(instance);
console.log("exit: ", exitCode);

return {
exitCode,
Expand All @@ -44,6 +46,7 @@ export async function executeVm(callData: VmCallData, notifierBuffer: SharedArra
resultAsString: new TextDecoder().decode(vmImports.result),
}
} catch (err) {
console.log('Exception thrown', err);
console.error(`
@executeWasm
Exception threw: ${err}
Expand Down
2 changes: 2 additions & 0 deletions libs/vm/src/worker-host-communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export class HostToWorker {
const notifierBufferi32 = new Int32Array(this.notifierBuffer);
notifierBufferi32.set([this.actionResult.length], 1);

console.error("setted buffer, ready to send");

updateNotifierState(notifierBufferi32, AtomicState.ResponseResultLength);
}

Expand Down
20 changes: 12 additions & 8 deletions libs/vm/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import {
} from './types/worker-messages.js';

parentPort?.on('message', async function (event) {
const message: WorkerMessage = event;
try {
const message: WorkerMessage = event;

if (message.type === WorkerMessageType.VmCall) {
const result = await executeVm(message.callData, message.notifierBuffer);
const response: VmResultWorkerMessage = {
result,
type: WorkerMessageType.VmResult,
};
if (message.type === WorkerMessageType.VmCall) {
const result = await executeVm(message.callData, message.notifierBuffer);
const response: VmResultWorkerMessage = {
result,
type: WorkerMessageType.VmResult,
};

parentPort?.postMessage(response);
parentPort?.postMessage(response);
}
} catch (error) {
console.error("@worker:message, error thrown: ", error);
}
});

0 comments on commit 4ef493a

Please sign in to comment.