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

(2967) Generate unique references in organisation factory #2272

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

CristinaRO
Copy link
Collaborator

@CristinaRO CristinaRO commented Nov 30, 2023

Changes in this PR

  • Use Faker's unique feature to guarantee unique strings for the iati_reference and beis_organisation_reference in the organisation factory.

We have seen the test suite fail with an intermittent failure, unrelated to actual code failure, caused by the organisation created failing the uniqueness check for its iati_reference:

ActiveRecord::RecordInvalid:
Validation failed: Iati reference Iati reference has already been taken

E.g. https://github.com/UKGovernmentBEIS/beis-report-official-development-assistance/actions/runs/6978961311/job/18991313569

We suspect this intermittent failure is caused by Faker's pseudo-random generator accidentally producing the same string within the same spec. The IATI reference and BEIS organisation reference are more susceptible to this, because the randomly generated sequences are only 5 characters long.

Using Faker's unique feature means it's also a good idea to clear the record of unique values that have been returned between each spec, to avoid running out of combinations. (Not statistically likely, but why take chances?)

Screenshots of UI changes

N/A

Next steps

  • Is an ADR required? An ADR should be added if this PR introduces a change to the architecture.
  • Is a changelog entry required? An entry should always be made in CHANGELOG.md, unless this PR is a small tweak which has no impact outside the development team.
  • Do any environment variables need amending or adding?
  • Have any changes to the XML been checked with the IATI validator? See XML Validation

@CristinaRO
Copy link
Collaborator Author

@CristinaRO CristinaRO requested a review from mec December 1, 2023 11:13
Copy link
Collaborator

@mec mec left a comment

Choose a reason for hiding this comment

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

🚢

Use Faker's `unique` feature to guarantee unique strings for the
`iati_reference` and `beis_organisation_reference` in the organisation
factory.

We have seen the test suite fail with an intermittent failure, unrelated
to actual code failure, caused by the organisation created failing the
uniqueness check for its `iati_reference`:

```
ActiveRecord::RecordInvalid:
Validation failed: Iati reference Iati reference has already been taken
```

E.g. https://github.com/UKGovernmentBEIS/beis-report-official-development-assistance/actions/runs/6978961311/job/18991313569

We suspect this intermittent failure is caused by Faker's pseudo-random
generator accidentally producing the same string within the same spec.
The IATI reference and BEIS organisation reference are more susceptible
to this, because the randomly generated sequences are only 5 characters
long.

Using Faker's unique feature means it's also a good idea to clear the
record of unique values that have been returned between each spec, to
avoid running out of combinations. (Not statistically likely, but why
take chances?)
@CristinaRO CristinaRO merged commit a666e8d into develop Dec 4, 2023
2 checks passed
@CristinaRO CristinaRO deleted the flaky-specs-iati_reference branch December 4, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants