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 e622242
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 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
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
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 e622242

Please sign in to comment.