Skip to content

Commit

Permalink
Drop cursor from e2e test (#7)
Browse files Browse the repository at this point in the history
The cursor actually doesn't make sense here because the test event we're
looking for will always be on the first page; we just want to query the
first page over and over until it's there. Testing pagination will be a
little more involved
  • Loading branch information
Nicole White authored Aug 17, 2023
1 parent 3d3d004 commit 97d1c75
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions e2e/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,45 @@ const main = async () => {
throw new Error('AUTOBLOCKS_INGESTION_KEY env var is required.');
}

const traceId = crypto.randomUUID();
const tracer = new AutoblocksTracer(AUTOBLOCKS_INGESTION_KEY, { traceId });
const tracer = new AutoblocksTracer(AUTOBLOCKS_INGESTION_KEY);
const client = new AutoblocksAPIClient(AUTOBLOCKS_API_KEY);

await tracer.sendEvent(E2E_TESTS_EXPECTED_MESSAGE);

// Make sure our view exists
const views = await client.getViews();
if (!views.some((view) => view.id === E2E_TESTS_VIEW_ID)) {
throw new Error(`View ${E2E_TESTS_VIEW_ID} not found!`);
}

// Send test event
const testTraceId = crypto.randomUUID();
await tracer.sendEvent(E2E_TESTS_EXPECTED_MESSAGE, { traceId: testTraceId });

// Find the test event we just sent
let cursor: string | undefined = undefined;
let retries = 10;

while (retries > 0) {
const { nextCursor, traces } = await client.getTracesFromView({
const { traces } = await client.getTracesFromView({
viewId: E2E_TESTS_VIEW_ID,
pageSize: 10,
cursor,
});

console.log('Found traces:');
console.log(traces.map((t) => t.id));

if (traces.some((t) => t.id === traceId)) {
console.log(`Found trace ${traceId}!`);
if (traces.some((t) => t.id === testTraceId)) {
console.log(`Found trace ${testTraceId}!`);
break;
}

retries--;

if (retries === 0) {
throw new Error(`Couldn't find trace ${traceId}.`);
throw new Error(`Couldn't find trace ${testTraceId}.`);
}

cursor = nextCursor;

const sleepSeconds = 5;
console.log(
`Couldn't find trace ${traceId} yet, waiting ${sleepSeconds} seconds. ${retries} tries left.`,
`Couldn't find trace ${testTraceId} yet, waiting ${sleepSeconds} seconds. ${retries} tries left.`,
);
await sleep(sleepSeconds);
}
Expand Down

0 comments on commit 97d1c75

Please sign in to comment.