Skip to content

Commit

Permalink
test: update traceable execution tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tabkram committed Nov 22, 2023
1 parent ed3c62f commit 5987a20
Showing 1 changed file with 92 additions and 85 deletions.
177 changes: 92 additions & 85 deletions src/trace/traceableExecution.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TraceableExecution } from "./traceableExecution";
import { NodeData } from "./trace.model";

describe("TraceableExecution", () => {
let traceableExecution: TraceableExecution;
Expand Down Expand Up @@ -49,91 +50,97 @@ describe("TraceableExecution", () => {

// Perform assertions on the finalTrace
expect(finalTrace?.length).toEqual(5);

expect(finalTrace?.filter((n) => n.group === "nodes")).toEqual(3);
expect(finalTrace?.filter((n) => n.group === "edges")).toEqual(2);
});

// it('should create a trace of fetching data simultaneously from two functions using Promise.all', async () => {
// async function fetchCurrentTemperature(city: string) {
// return Promise.resolve(`Current Temperature in ${city}: 25°C`);
// }
//
// async function fetchDailyForecast(city: string) {
// return Promise.resolve(`Daily Forecast in ${city}: Sunny`);
// }
//
// async function getWeatherInformation(city: string, trace?: NodeData) {
// const [temperature, forecast] = await Promise.all([
// (
// await traceableExecution.run(fetchCurrentTemperature, [city], {
// trace: { parent: trace?.id },
// config: { parallel: true, traceExecution: true }
// })
// )?.outputs,
// (
// await traceableExecution.run(fetchDailyForecast, [city], {
// trace: { parent: trace?.id },
// config: { parallel: true, traceExecution: true }
// })
// )?.outputs
// ]);
//
// return Promise.resolve(`Weather information: ${temperature}, ${forecast}`);
// }
//
// // Simulate some parallel execution
// await traceableExecution.run(getWeatherInformation, ['Paris']);
// // Retrieve the trace
// const finalTrace = traceableExecution.getTrace();
// // Perform assertions on the finalTrace
// expect(finalTrace).toMatchObject([
// {
// data: {
// id: expect.stringMatching(/^getWeatherInformation_.*$/),
// label: 'getWeatherInformation',
// parallel: false,
// abstract: false,
// createTime: expect.any(Date),
// inputs: ['Paris'],
// outputs: 'Weather information: Current Temperature in Paris: 25°C, Daily Forecast in Paris: Sunny',
// startTime: expect.any(Date),
// endTime: expect.any(Date),
// duration: expect.any(Number),
// updateTime: expect.any(Date)
// },
// group: 'nodes'
// },
// {
// data: {
// inputs: ['Paris'],
// outputs: 'Current Temperature in Paris: 25°C',
// startTime: expect.any(Date),
// endTime: expect.any(Date),
// duration: expect.any(Number),
// id: expect.stringMatching(/^fetchCurrentTemperature_.*$/),
// label: '1 - fetchCurrentTemperature',
// parent: expect.stringMatching(/^getWeatherInformation_.*$/),
// parallel: true,
// abstract: false,
// createTime: expect.any(Date)
// },
// group: 'nodes'
// },
// {
// data: {
// inputs: ['Paris'],
// outputs: 'Daily Forecast in Paris: Sunny',
// startTime: expect.any(Date),
// endTime: expect.any(Date),
// duration: expect.any(Number),
// id: expect.stringMatching(/^fetchDailyForecast_.*$/),
// label: '3 - fetchDailyForecast',
// parent: expect.stringMatching(/^getWeatherInformation_.*$/),
// parallel: true,
// abstract: false,
// createTime: expect.any(Date)
// },
// group: 'nodes'
// }
// ]);
// });
it("should create a trace of fetching data simultaneously from two functions using Promise.all", async () => {

Check failure on line 57 in src/trace/traceableExecution.spec.ts

View workflow job for this annotation

GitHub Actions / Tests annotations (🧪 jest-coverage-report-action)

TraceableExecution > should create a trace of fetching data simultaneously from two functions using Promise.all

Error: expect(received).toEqual(expected) // deep equality Expected: 3 Received: [{"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.052Z, "duration": 1, "endTime": 2023-11-22T21:37:53.052Z, "errors": undefined, "id": "getWeatherInformation_1700689073051_b5df6ef5-fd99-4269-8f0b-ebf65671591d", "inputs": ["Paris"], "label": "getWeatherInformation", "narratives": undefined, "outputs": "Weather information: Current Temperature in Paris: 25°C, Daily Forecast in Paris: Sunny", "parallel": false, "startTime": 2023-11-22T21:37:53.051Z, "updateTime": 2023-11-22T21:37:53.052Z}, "group": "nodes"}, {"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.052Z, "duration": 1, "endTime": 2023-11-22T21:37:53.052Z, "id": "fetchCurrentTemperature_1700689073051_7ee00c7e-e9e6-4239-9a01-d72204b2c8e1", "inputs": ["Paris"], "label": "1 - fetchCurrentTemperature", "narratives": undefined, "outputs": "Current Temperature in Paris: 25°C", "parallel": true, "parent": "getWeatherInformation_1700689073051_b5df6ef5-fd99-4269-8f0b-ebf65671591d", "startTime": 2023-11-22T21:37:53.051Z}, "group": "nodes"}, {"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.052Z, "duration": 0, "endTime": 2023-11-22T21:37:53.052Z, "id": "fetchDailyForecast_1700689073052_13ca15cb-c995-47bd-bc4a-9bc2813cfcff", "inputs": ["Paris"], "label": "3 - fetchDailyForecast", "narratives": undefined, "outputs": "Daily Forecast in Paris: Sunny", "parallel": true, "parent": "getWeatherInformation_1700689073051_b5df6ef5-fd99-4269-8f0b-ebf65671591d", "startTime": 2023-11-22T21:37:53.052Z}, "group": "nodes"}] at Object.<anonymous> (/home/runner/work/execution-engine/execution-engine/src/trace/traceableExecution.spec.ts:91:60) at processTicksAndRejections (node:internal/process/task_queues:95:5)
async function fetchCurrentTemperature(city: string) {
return Promise.resolve(`Current Temperature in ${city}: 25°C`);
}

async function fetchDailyForecast(city: string) {
return Promise.resolve(`Daily Forecast in ${city}: Sunny`);
}

async function getWeatherInformation(city: string, trace?: NodeData) {
const [temperature, forecast] = await Promise.all([
(
await traceableExecution.run(fetchCurrentTemperature, [city], {
trace: { parent: trace?.id },
config: { parallel: true, traceExecution: true },
})
)?.outputs,
(
await traceableExecution.run(fetchDailyForecast, [city], {
trace: { parent: trace?.id },
config: { parallel: true, traceExecution: true },
})
)?.outputs,
]);

return Promise.resolve(
`Weather information: ${temperature}, ${forecast}`
);
}

// Simulate some parallel execution
await traceableExecution.run(getWeatherInformation, ["Paris"]);
// Retrieve the trace
const finalTrace = traceableExecution.getTrace();
expect(finalTrace?.filter((n) => n.group === "nodes")).toEqual(3);
expect(finalTrace?.filter((n) => n.group === "edges")).toEqual(0);
// Perform assertions on the finalTrace
expect(finalTrace).toMatchObject([
{
data: {
id: expect.stringMatching(/^getWeatherInformation_.*$/),
label: "getWeatherInformation",
parallel: false,
abstract: false,
createTime: expect.any(Date),
inputs: ["Paris"],
outputs:
"Weather information: Current Temperature in Paris: 25°C, Daily Forecast in Paris: Sunny",
startTime: expect.any(Date),
endTime: expect.any(Date),
duration: expect.any(Number),
updateTime: expect.any(Date),
},
group: "nodes",
},
{
data: {
inputs: ["Paris"],
outputs: "Current Temperature in Paris: 25°C",
startTime: expect.any(Date),
endTime: expect.any(Date),
duration: expect.any(Number),
id: expect.stringMatching(/^fetchCurrentTemperature_.*$/),
label: "1 - fetchCurrentTemperature",
parent: expect.stringMatching(/^getWeatherInformation_.*$/),
parallel: true,
abstract: false,
createTime: expect.any(Date),
},
group: "nodes",
},
{
data: {
inputs: ["Paris"],
outputs: "Daily Forecast in Paris: Sunny",
startTime: expect.any(Date),
endTime: expect.any(Date),
duration: expect.any(Number),
id: expect.stringMatching(/^fetchDailyForecast_.*$/),
label: "3 - fetchDailyForecast",
parent: expect.stringMatching(/^getWeatherInformation_.*$/),
parallel: true,
abstract: false,
createTime: expect.any(Date),
},
group: "nodes",
},
]);
});
});

1 comment on commit 5987a20

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/npx' failed with exit code 1
St.
Category Percentage Covered / Total
🔴 Statements 57.95% 113/195
🔴 Branches 49.23% 64/130
🟡 Functions 63.16% 36/57
🔴 Lines 58.73% 111/189

Test suite run failed

Failed tests: 2/11. Failed suites: 1/3.
  ● TraceableExecution › should create a trace of consecutive calls

    expect(received).toEqual(expected) // deep equality

    Expected: 3
    Received: [{"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.035Z, "duration": 1, "endTime": 2023-11-22T21:37:53.035Z, "id": "registerUser_1700689073034_96a89e9f-d718-4c0e-8461-7d55d4b939d2", "inputs": ["john_doe", "secure_password"], "label": "registerUser", "narratives": undefined, "outputs": "User john_doe successfully registered", "parallel": false, "startTime": 2023-11-22T21:37:53.034Z}, "group": "nodes"}, {"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.035Z, "duration": 0, "endTime": 2023-11-22T21:37:53.035Z, "id": "loginUser_1700689073035_0c820415-a0c6-420f-9697-b8d35b1a4210", "inputs": ["john_doe", "secure_password"], "label": "loginUser", "narratives": undefined, "outputs": "User john_doe successfully logged in", "parallel": false, "startTime": 2023-11-22T21:37:53.035Z}, "group": "nodes"}, {"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.035Z, "duration": 0, "endTime": 2023-11-22T21:37:53.035Z, "id": "getUserInformation_1700689073035_6dc74fb6-6f34-485d-954d-292f0d930675", "inputs": ["john_doe"], "label": "getUserInformation", "narratives": undefined, "outputs": "User Information for john_doe: Full Name - John Doe, Email - john.doe@example.com, Role - User", "parallel": false, "startTime": 2023-11-22T21:37:53.035Z}, "group": "nodes"}]

      51 |     // Perform assertions on the finalTrace
      52 |     expect(finalTrace?.length).toEqual(5);
    > 53 |     expect(finalTrace?.filter((n) => n.group === "nodes")).toEqual(3);
         |                                                            ^
      54 |     expect(finalTrace?.filter((n) => n.group === "edges")).toEqual(2);
      55 |   });
      56 |

      at Object.<anonymous> (src/trace/traceableExecution.spec.ts:53:60)

  ● TraceableExecution › should create a trace of fetching data simultaneously from two functions using Promise.all

    expect(received).toEqual(expected) // deep equality

    Expected: 3
    Received: [{"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.052Z, "duration": 1, "endTime": 2023-11-22T21:37:53.052Z, "errors": undefined, "id": "getWeatherInformation_1700689073051_b5df6ef5-fd99-4269-8f0b-ebf65671591d", "inputs": ["Paris"], "label": "getWeatherInformation", "narratives": undefined, "outputs": "Weather information: Current Temperature in Paris: 25°C, Daily Forecast in Paris: Sunny", "parallel": false, "startTime": 2023-11-22T21:37:53.051Z, "updateTime": 2023-11-22T21:37:53.052Z}, "group": "nodes"}, {"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.052Z, "duration": 1, "endTime": 2023-11-22T21:37:53.052Z, "id": "fetchCurrentTemperature_1700689073051_7ee00c7e-e9e6-4239-9a01-d72204b2c8e1", "inputs": ["Paris"], "label": "1 - fetchCurrentTemperature", "narratives": undefined, "outputs": "Current Temperature in Paris: 25°C", "parallel": true, "parent": "getWeatherInformation_1700689073051_b5df6ef5-fd99-4269-8f0b-ebf65671591d", "startTime": 2023-11-22T21:37:53.051Z}, "group": "nodes"}, {"data": {"abstract": false, "createTime": 2023-11-22T21:37:53.052Z, "duration": 0, "endTime": 2023-11-22T21:37:53.052Z, "id": "fetchDailyForecast_1700689073052_13ca15cb-c995-47bd-bc4a-9bc2813cfcff", "inputs": ["Paris"], "label": "3 - fetchDailyForecast", "narratives": undefined, "outputs": "Daily Forecast in Paris: Sunny", "parallel": true, "parent": "getWeatherInformation_1700689073051_b5df6ef5-fd99-4269-8f0b-ebf65671591d", "startTime": 2023-11-22T21:37:53.052Z}, "group": "nodes"}]

      89 |     // Retrieve the trace
      90 |     const finalTrace = traceableExecution.getTrace();
    > 91 |     expect(finalTrace?.filter((n) => n.group === "nodes")).toEqual(3);
         |                                                            ^
      92 |     expect(finalTrace?.filter((n) => n.group === "edges")).toEqual(0);
      93 |     // Perform assertions on the finalTrace
      94 |     expect(finalTrace).toMatchObject([

      at Object.<anonymous> (src/trace/traceableExecution.spec.ts:91:60)

Report generated by 🧪jest coverage report action from 5987a20

Please sign in to comment.