Skip to content

Commit

Permalink
build: fixed pg test case failure issue (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryamohanan authored Aug 24, 2023
1 parent c80eca6 commit aaeb8ca
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/collector/test/tracing/database/pg/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,50 @@ app.get('/quick-query', (req, res) => {
}
});
});
app.get('/asynchronous-query', async (req, res) => {
try {
const firstQueryResults = await executeSelectDateQuery();
const secondQueryResults = executeLongRunningQuery(); // Not waiting for the results
const thirdQueryResults = inserUser(); // Not waiting for the results

const combinedResults = {
firstQuery: firstQueryResults,
secondQuery: secondQueryResults,
thirdQuery: thirdQueryResults
};
request(`http://127.0.0.1:${agentPort}`).then(() => {
res.json(combinedResults);
});
} catch (err) {
log('Failed to execute queries', err);
res.sendStatus(500);
}
});

async function executeSelectDateQuery() {
return client.query('SELECT NOW()');
}

async function executeLongRunningQuery() {
try {
await client.query('SELECT NOW() FROM pg_sleep(2)');
return 'Long-running query executed successfully.';
} catch (err) {
log('Failed to execute long-running query', err);
}
}

async function inserUser() {
const insert = 'INSERT INTO users(name, email) VALUES($1, $2) RETURNING *';
const values = ['beaker', '[email protected]'];

try {
await client.query(insert, values);
return 'User inserted successfully.';
} catch (err) {
log('Failed to insert user', err);
}
}
app.listen(port, () => {
log(`Listening on port: ${port}`);
});
Expand Down

0 comments on commit aaeb8ca

Please sign in to comment.