Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Fix random IDs - #6302

Closed
Dreamsorcerer wants to merge 8 commits into
TechEmpower:masterfrom
Dreamsorcerer:patch-3
Closed

Dreamsorcerer wants to merge 8 commits into
TechEmpower:masterfrom
Dreamsorcerer:patch-3

Conversation

@Dreamsorcerer

@Dreamsorcerer Dreamsorcerer commented Jan 18, 2021 •

Copy link
Copy Markdown
Contributor

Avoid duplicate IDs in Python tests.

Is it permittable to randomise it once at the top of the file, and avoid doing any random functions within the handlers?

@Dreamsorcerer

Dreamsorcerer commented Jan 18, 2021 •

Copy link
Copy Markdown
Contributor Author

Appears this fails to fix the issue. Looks like all the python examples consistently get to:
Rows updated: 10128/10240

But, sometimes aiohttp comes out at 10126, which then fails the test. I suspect this is because of the random value being set. When we update the values, we pick a random number between 0-10000 and update the object. If that number is the same as the previously set number, then I'd expect sqlalchemy to drop the update statement again (as it achieves nothing).
With over 10000 updates happening, it's normal to have anywhere from 0-2 dropped in each run.

Judging by the above test runs, I'd say it has a little over 50% chance of failing.

@Dreamsorcerer

Copy link
Copy Markdown
Contributor Author

@nbrady-techempower ^^^

@Dreamsorcerer

Copy link
Copy Markdown
Contributor Author

Running the maths, there should be only a 36% chance that 0 collisions happen and the test succeeds.

@NateBrady23

Copy link
Copy Markdown
Member

Is it permittable to randomise it once at the top of the file, and avoid doing any random functions within the handlers?

There needs to be a mechanism in place that replenishes this array with a new set of randomly ordered numbers in the event is it exhausted.

Appears this fails to fix the issue.

It may be worthwhile to wait a few days. We're still in the process of switching over to the new toolset and this might give you more insight into what's happening.

@Dreamsorcerer

Dreamsorcerer commented Jan 18, 2021 •

Copy link
Copy Markdown
Contributor Author

Is it permittable to randomise it once at the top of the file, and avoid doing any random functions within the handlers?

There needs to be a mechanism in place that replenishes this array with a new set of randomly ordered numbers in the event is it exhausted.

The current code just reuses the beginning of the array every time. So, multiple requests would get the same set of IDs. So, my question is more does it have to be shuffled on every request to give a different set of ids (or is once per application startup enough)?

It may be worthwhile to wait a few days. We're still in the process of switching over to the new toolset and this might give you more insight into what's happening.

Given the frequency, my theory that it is caused by the random number matching the existing value in the DB seems pretty likely. If a single update is missing, the test fails.

@NateBrady23

Copy link
Copy Markdown
Member

The current code just reuses the beginning of the array every time. So, multiple requests would get the same set of IDs. So, my question is more does it have to be shuffled on every request to give a different set of ids?

Yes, it needs to be randomized on each request.

@NateBrady23

Copy link
Copy Markdown
Member

Hey @Dreamsorcerer ! It's been a bit since we talked about this. Any time to take a look at it or should I close it up for now?

@Dreamsorcerer

Copy link
Copy Markdown
Contributor Author

Well, I don't know how to fix the issue, as I mentioned before the tests should probably fail with about a 64% chance. I'm not sure if there's maybe some option to sqlalchemy or something that could disable the optimisations, otherwise I don't see a fix.

Feel free to close the PR given that it doesn't resolve the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants