Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review StoredProc Reaction #103

Merged
merged 32 commits into from
Nov 8, 2024

Conversation

ruokun-niu
Copy link
Contributor

@ruokun-niu ruokun-niu commented Oct 30, 2024

Description

  • Updated storedproc reaction provider
  • StoredProc now accepts three different comands: AddedResultCommand, UpdatedResultCommand and DeletedResultCommand
  • Added comments
  • Created a test for the storedproc reaction in the e2e folder
    • The storedproc test scenario uses the same postgres database as the simple-scenario, but it uses its own source, queries and reaction

Type of change

  • This pull request fixes a bug in Drasi and has an approved issue (issue link required).

Fixes: (https://dev.azure.com/azure-octo/Incubations/_boards/board/t/Drasi/User%20Stories?workitem=12558)

@ruokun-niu ruokun-niu marked this pull request as ready for review November 4, 2024 21:09
@ruokun-niu ruokun-niu requested a review from a team as a code owner November 4, 2024 21:09
reactions/sql/storedproc-reaction/src/index.ts Outdated Show resolved Hide resolved
reactions/sql/storedproc-reaction/src/index.ts Outdated Show resolved Hide resolved
console.log(`Executing the stored proc: ${query}`);

// Execute the query
knex.raw(query).then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

you could make this function async and use await

/**
* @param {Array} queryIds
*/
function storedprocReactionManifest(queryIds) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be pure yaml in the directory of your specific scenario



test('Test StoredProc Reaction - AddedResultCommand', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a new scenario instead of extending the simple scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I investigated this a bit more and found out that jest actually does not allow two test scenarios to run sequentially. This sometimes caused a race condition in the postgres database and the e2e test to fail.

I think maybe it is better to move the setup of the postgres database outside of the individual test scenarios and include it as a part of the cluster setup process?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better if scenarios did not share things. We could use different DNS names for different PG instances. I think you can run tests serially with jest: https://jestjs.io/docs/cli#--runinband

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha so one postgres per scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on it right now

@ruokun-niu ruokun-niu changed the title Draft: Review StoredProc Reaction Review StoredProc Reaction Nov 4, 2024
Copy link
Contributor

@danielgerlag danielgerlag left a comment

Choose a reason for hiding this comment

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

You might also need to look into doing some kind of teardown per scenario, before it starts the next scenario.




CREATE TABLE "CommandResult" (
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The storedprocedure adds an item to this table. This is used to verify that the storedproc reaction is working

Copy link
Contributor

Choose a reason for hiding this comment

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

but this is on the wrong scenario?

Copy link
Contributor Author

@ruokun-niu ruokun-niu Nov 5, 2024

Choose a reason for hiding this comment

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

Yeah I am moving this yaml

#103 (comment)

await dbClient.query(`INSERT INTO "Item" ("ItemId", "Name", "Category") VALUES (3, 'Drasi', '1')`);

// sleep 35 seconds
await new Promise(r => setTimeout(r, 15000));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a better way we can do this rather than sleeping 35 seconds?
Could we check every 1 second and timeout after 30 seconds?
Something like the .waitForChange on on the signalr fixture.

reactions/sql/storedproc-reaction/src/index.ts Outdated Show resolved Hide resolved
await knex.raw(query);
console.log("The query was executed successfully");
} catch (error) {
console.log(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

If it fails, we probably want the exception to bubble up to the event handler, so that it will return a 500 error back to DAPR, so that the message will not be acknowledged off the queue.

Copy link
Contributor

@danielgerlag danielgerlag left a comment

Choose a reason for hiding this comment

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

Looking good

@ruokun-niu ruokun-niu merged commit 4caf463 into drasi-project:main Nov 8, 2024
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants