-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: fixed pg test case failure issue (#852)
- Loading branch information
1 parent
c80eca6
commit aaeb8ca
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}`); | ||
}); | ||
|