Skip to content

Stabilize GroupsController and Address Flaky Test Issues #6836

@aaronlippold

Description

@aaronlippold

Description:

The CI job for the GroupsController has encountered the following issues:

Database Deadlock:

Deadlocks were observed in the GroupUsers table during deletion operations.
Likely caused by concurrent transactions acquiring locks in different orders.

Flaky Test in GroupsController:

The test should stop regular users and others from updating a group failed intermittently.
This might occur due to reliance on shared database state and improper isolation.

Duplicate Key Violation:

A duplicate key error was observed on the Users_email_key constraint.
Indicates that the database state is not properly reset between tests.

Proposed Solutions:

  1. Fix Deadlocks:
    Ensure consistent locking order and use explicit transactions.
    Example:
await this.databaseService.sequelize.transaction(async (transaction) => {
  await this.groupUserModel.destroy({ where: { groupId }, transaction });
});
  1. Improve Test Isolation:
    Reset the database state properly in beforeEach() hooks.
    Example:
beforeEach(async () => {
  await databaseService.cleanAll();
  basicUser = await usersService.create(CREATE_USER_DTO_TEST_OBJ);
});
  1. Handle Duplicate Key Errors:
    Use UPSERT or check for existing records before insertion.
    Example:
await this.userModel.upsert({ email: 'example@example.com' }, { conflictFields: ['email'] });
  1. Improve Test Assertions:

Ensure the ForbiddenError is reliably thrown and validated.
Example:

await expect(
  groupsController.update({ user: basicUser }, privateGroup.id, UPDATE_GROUP)
).rejects.toThrow('You do not have permission to update this group');

Additional Context:

The failure logs can be found here.

Metadata

Metadata

Labels

bugSomething isn't workingtesting

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions