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

fix(tests): Fix broken integration test that never fails in CI #3115

Merged
merged 4 commits into from
Dec 5, 2024

Conversation

nalanj
Copy link
Contributor

@nalanj nalanj commented Dec 4, 2024

This was a weird one. Since I've joined I've always had some tests that fail on my computer but never fail in CI. There's another that's flaky for me, but I can't seem to get it to fail right now.

This test was failing for me:

it('should update the end user if needed', async () => {
// first request create an end user
const endUserId = 'knownId';
const res = await api.fetch(endpoint, {
method: 'POST',
token: seed.env.secret_key,
body: { end_user: { id: endUserId, email: '[email protected]' } }
});
isSuccess(res.json);
// second request with same endUserId update the end user
const newEmail = '[email protected]';
const newDisplayName = 'Mr XY';
const newOrgId = 'orgId';
const newOrgDisplayName = 'OrgName';
const res2 = await api.fetch(endpoint, {
method: 'POST',
token: seed.env.secret_key,
body: {
end_user: {
id: endUserId,
email: newEmail,
display_name: newDisplayName
},
organization: { id: newOrgId, display_name: newOrgDisplayName }
}
});
isSuccess(res2.json);
const getEndUser = await endUserService.getEndUser(db.knex, {
endUserId: endUserId,
accountId: seed.env.account_id,
environmentId: seed.env.id
});
const endUser = getEndUser.unwrap();
expect(endUser.email).toBe(newEmail);
expect(endUser.displayName).toBe(newDisplayName);
expect(endUser.organization?.organizationId).toBe(newOrgId);
expect(endUser.organization?.displayName).toBe(newOrgDisplayName);
});

The source of the issue, I found, was that we were replying in the server inside of a transaction block, so the transaction hadn't finalized by the time that my request replied and the test checked that the database was updated. This PR pulls the http response sending outside of the transaction block to make sure everything times out correctly.

I couldn't find any other examples where we did this.

How I tested it

Run the tests!

Copy link
Collaborator

@TBonnin TBonnin left a comment

Choose a reason for hiding this comment

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

lgtm. This is probably not the only place in the codebase where we send response back from inside a db transaction

@nalanj
Copy link
Contributor Author

nalanj commented Dec 4, 2024

@TBonnin I actually dug around some and couldn't find any other instances, but that was also my assumption.

@nalanj nalanj marked this pull request as ready for review December 4, 2024 21:28
@nalanj nalanj self-assigned this Dec 4, 2024
Copy link
Collaborator

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

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

Indeed

@nalanj nalanj merged commit 2379484 into master Dec 5, 2024
21 checks passed
@nalanj nalanj deleted the alan/test-trx-fix branch December 5, 2024 13:24
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