Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Randomize test order for unit tests #3108

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

Merged
merged 7 commits into from
May 22, 2025

Conversation

stephenfin
Copy link
Contributor

@stephenfin stephenfin commented Jul 16, 2024

I don't know why this isn't the default behavior, but relying on test order is a bad idea (TM) that we should do our best to avoid.

This is currently only done for unit tests so that we can actually get something merged. We can extend to acceptance tests in a subsequent PR.

Copy link
Contributor

@mandre mandre left a comment

Choose a reason for hiding this comment

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

I'm all for it but we might want to trigger all the jobs on this PR before merging.

@github-actions github-actions bot added semver:patch No API change and removed semver:patch No API change labels Jul 16, 2024
@stephenfin
Copy link
Contributor Author

Looks like I've just uncovered a whole class of bugs 😂 😭

@github-actions github-actions bot added semver:minor Backwards-compatible change and removed semver:patch No API change labels Jul 17, 2024
@stephenfin stephenfin force-pushed the randomise-tests branch 2 times, most recently from 2e7bd84 to d96065f Compare July 17, 2024 12:09
@github-actions github-actions bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Jul 17, 2024
@coveralls
Copy link

coveralls commented Jul 17, 2024

Coverage Status

coverage: 78.747%. remained the same
when pulling d96065f on shiftstack:randomise-tests
into d56b260 on gophercloud:master.

@github-actions github-actions bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Jul 17, 2024
@mandre
Copy link
Contributor

mandre commented Jul 17, 2024

Regarding your first commit (c7bacba), this was done on purpose in #2811 and #2814 to limit our public API.

I've checked again today, and indeed go-apidiff looks at diff the testing packages.

@stephenfin
Copy link
Contributor Author

Regarding your first commit (c7bacba), this was done on purpose in #2811 and #2814 to limit our public API.

I've checked again today, and indeed go-apidiff looks at diff the testing packages.

Fair. I have removed this now.

@github-actions github-actions bot added semver:major Breaking change and removed semver:minor Backwards-compatible change labels Jul 17, 2024
@github-actions github-actions bot added semver:major Breaking change and removed semver:major Breaking change labels Jul 17, 2024
@pierreprinetti pierreprinetti added good first issue A good issue for first-time contributors and removed good first issue A good issue for first-time contributors labels Jul 18, 2024
Global tests objects are harmful, in so far as any attempt to modify
them can result in failures further down the food chain. Don't use them
and instead generate new objects on the fly.

Signed-off-by: Stephen Finucane <[email protected]>
The fake service clients rely on the fake server being initialised, even
if we don't actually use it. Add the missing calls, renaming some tests
in the process.

PS: You can reproduce this without the '-shuffle on' by simply deleting
any of the test cases preceding those that we are modifying here and
running the tests.

Signed-off-by: Stephen Finucane <[email protected]>
Ahead of some large-scale rework here.

Signed-off-by: Stephen Finucane <[email protected]>
All aliases were discovered with:

    ag '[^\t]"github.com/gophercloud/gophercloud/v2/testhelper/client"'

They were then replaced with judicious use of sed and ag. Starting with
the most common alias, 'fake', first replace the alias:

    sed -i 's/\<fake\>/client/' $(ag 'fake "github.com/gophercloud/gophercloud/v2/testhelper/client"' -l)

This was repeated for the other aliases, 'fakeclient' and 'thclient'. We
then dropped the now unnecessary aliasing:

    sed -i 's/\<client\> "/"/' $(ag 'client "github.com/gophercloud/gophercloud/v2/testhelper/client"' -l)

Signed-off-by: Stephen Finucane <[email protected]>
@github-actions github-actions bot added edit:db This PR updates db code edit:loadbalancer This PR updates loadbalancer code edit:compute This PR updates compute code edit:keymanager This PR updates keymanager code edit:utils This PR updates utils code edit:messaging This PR updates messaging code edit:containerinfra This PR updates containerinfra code edit:placement This PR updates placement code edit:objectstorage This PR updates objectstorage code edit:workflow This PR updates workflow code edit:sharedfilesystems This PR updates sharedfilesystems code edit:baremetal This PR updates baremetal code edit:gophercloud This PR updates common Gophercloud code edit:blockstorage This PR updates blockstorage code edit:identity This PR updates identity code edit:container This PR updates container code edit:baremetalintrospection This PR updates baremetalintrospection code edit:testinfra This PR updates testing infrastructure code labels May 20, 2025
I don't know why this isn't the default behavior, but relying on test
order is a bad idea (TM) that we should do our best to avoid.

Signed-off-by: Stephen Finucane <[email protected]>
@stephenfin stephenfin changed the title Randomize test order Randomize test order for unit tests May 20, 2025
@stephenfin
Copy link
Contributor Author

Weird: the designate dalmatian job failed to deploy due to a missing dependency, but I haven't touched that and the upstream branch is mostly unchanged 😕

May 20 17:46:11 fv-az768-584 [email protected][75391]: *** uWSGI is running in multiple interpreter mode ***
May 20 17:46:11 fv-az768-584 [email protected][75391]: spawned uWSGI master process (pid: 75391)
May 20 17:46:11 fv-az768-584 systemd[1]: Started Devstack [email protected].
May 20 17:46:11 fv-az768-584 [email protected][75391]: spawned uWSGI worker 1 (pid: 75392, cores: 1)
May 20 17:46:11 fv-az768-584 [email protected][75391]: spawned uWSGI worker 2 (pid: 75393, cores: 1)
May 20 17:46:11 fv-az768-584 [email protected][75391]: running "unix_signal:15 gracefully_kill_them_all" (master-start)...
May 20 17:46:12 fv-az768-584 [email protected][75392]: Traceback (most recent call last):
May 20 17:46:12 fv-az768-584 [email protected][75392]:   File "/opt/stack/data/venv/bin/designate-api-wsgi", line 4, in <module>
May 20 17:46:12 fv-az768-584 [email protected][75392]:     __import__('pkg_resources').require('designate==19.0.1.dev8')
May 20 17:46:12 fv-az768-584 [email protected][75392]:   File "/opt/stack/data/venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1070, in require
May 20 17:46:12 fv-az768-584 [email protected][75392]:     needed = self.resolve(parse_requirements(requirements))
May 20 17:46:12 fv-az768-584 [email protected][75392]:   File "/opt/stack/data/venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 897, in resolve
May 20 17:46:12 fv-az768-584 [email protected][75392]:     dist = self._resolve_dist(
May 20 17:46:12 fv-az768-584 [email protected][75392]:   File "/opt/stack/data/venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 938, in _resolve_dist
May 20 17:46:12 fv-az768-584 [email protected][75392]:     raise DistributionNotFound(req, requirers)
May 20 17:46:12 fv-az768-584 [email protected][75392]: pkg_resources.DistributionNotFound: The 'oslo.utils>=4.7.0' distribution was not found and is required by designate, oslo.versionedobjects, tooz
May 20 17:46:12 fv-az768-584 [email protected][75392]: unable to load app 0 (mountpoint='') (callable not found or import error)
May 20 17:46:12 fv-az768-584 [email protected][75392]: *** no app loaded. going in full dynamic mode ***
May 20 17:46:12 fv-az768-584 [email protected][75392]: --- no python application found, check your startup logs for errors ---
May 20 17:46:12 fv-az768-584 [email protected][75392]: [pid: 75392|app: -1|req: -1/1] 127.0.0.1 () {32 vars in 388 bytes} [Tue May 20 17:46:12 2025] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 3 headers in 102 bytes (0 switches on core 0)
May 20 17:46:12 fv-az768-584 [email protected][75393]: Traceback (most recent call last):
May 20 17:46:12 fv-az768-584 [email protected][75393]:   File "/opt/stack/data/venv/bin/designate-api-wsgi", line 4, in <module>
May 20 17:46:12 fv-az768-584 [email protected][75393]:     __import__('pkg_resources').require('designate==19.0.1.dev8')
May 20 17:46:12 fv-az768-584 [email protected][75393]:   File "/opt/stack/data/venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1070, in require
May 20 17:46:12 fv-az768-584 [email protected][75393]:     needed = self.resolve(parse_requirements(requirements))
May 20 17:46:12 fv-az768-584 [email protected][75393]:   File "/opt/stack/data/venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 897, in resolve
May 20 17:46:12 fv-az768-584 [email protected][75393]:     dist = self._resolve_dist(
May 20 17:46:12 fv-az768-584 [email protected][75393]:   File "/opt/stack/data/venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 938, in _resolve_dist
May 20 17:46:12 fv-az768-584 [email protected][75393]:     raise DistributionNotFound(req, requirers)
May 20 17:46:12 fv-az768-584 [email protected][75393]: pkg_resources.DistributionNotFound: The 'oslo.utils>=4.7.0' distribution was not found and is required by designate, oslo.versionedobjects, tooz
May 20 17:46:12 fv-az768-584 [email protected][75393]: unable to load app 0 (mountpoint='') (callable not found or import error)
May 20 17:46:12 fv-az768-584 [email protected][75393]: *** no app loaded. going in full dynamic mode ***
May 20 17:46:33 fv-az768-584 [email protected][75392]: --- no python application found, check your startup logs for errors ---
May 20 17:46:33 fv-az768-584 [email protected][75392]: [pid: 75392|app: -1|req: -1/2] 127.0.0.1 () {40 vars in 721 bytes} [Tue May 20 17:46:33 2025] POST /v2/zones => generated 21 bytes in 0 msecs (HTTP/1.1 500) 3 headers in 102 bytes (0 switches on core 0)
May 20 17:46:33 fv-az768-584 [email protected][75393]: --- no python application found, check your startup logs for errors ---
May 20 17:46:33 fv-az768-584 [email protected][75393]: [pid: 75393|app: -1|req: -1/3] 127.0.0.1 () {40 vars in 721 bytes} [Tue May 20 17:46:33 2025] POST /v2/zones => generated 21 bytes in 0 msecs (HTTP/1.1 500) 3 headers in 102 bytes (0 switches on core 0)
May 20 17:46:33 fv-az768-584 [email protected][75392]: --- no python application found, check your startup logs for errors ---
May 20 17:46:33 fv-az768-584 [email protected][75392]: [pid: 75392|app: -1|req: -1/4] 127.0.0.1 () {40 vars in 721 bytes} [Tue May 20 17:46:33 2025] POST /v2/zones => generated 21 bytes in 0 msecs (HTTP/1.1 500) 3 headers in 102 bytes (0 switches on core 0)
May 20 17:46:33 fv-az768-584 [email protected][75393]: --- no python application found, check your startup logs for errors ---
May 20 17:46:33 fv-az768-584 [email protected][75393]: [pid: 75393|app: -1|req: -1/5] 127.0.0.1 () {40 vars in 721 bytes} [Tue May 20 17:46:33 2025] POST /v2/zones => generated 21 bytes in 0 msecs (HTTP/1.1 500) 3 headers in 102 bytes (0 switches on core 0)
May 20 17:46:33 fv-az768-584 [email protected][75392]: --- no python application found, check your startup logs for errors ---
May 20 17:46:33 fv-az768-584 [email protected][75392]: [pid: 75392|app: -1|req: -1/6] 127.0.0.1 () {40 vars in 721 bytes} [Tue May 20 17:46:33 2025] POST /v2/zones => generated 21 bytes in 0 msecs (HTTP/1.1 500) 3 headers in 102 bytes (0 switches on core 0)

I've rerun the job in case it was a once-off.

@stephenfin
Copy link
Contributor Author

stephenfin commented May 21, 2025

The networking test failed because of a duplicate security group rule. This is likely because we use RandomInt to generate random port ranges and these probably overlapped. We might need to hardcode these.

=== Failed
=== FAIL: internal/acceptance/openstack/networking/v2/extensions TestSecurityGroupsCreateUpdateDelete (0.91s)
    extensions.go:90: Attempting to create security group: TESTACC-zDuuhInP
    extensions.go:102: Created security group: 992f1e0d-cbb2-45dc-9595-8fa3866d665a
    extensions.go:114: Attempting to create security group rule in group: 992f1e0d-cbb2-45dc-9595-8fa3866d665a
    extensions.go:135: Created security group rule: 3a3073ed-b9d9-40a9-b767-fb2ebf3325ec
    extensions.go:147: Attempting to bulk create security group rules in group: 992f1e0d-cbb2-45dc-9595-8fa3866d665a
    security_test.go:31: Failure in security_test.go, line 31: unexpected error "Expected HTTP response code [201 202] when accessing [POST http://10.1.0.27:9696/networking/v2.0/security-group-rules], but got 409 instead: {\"NeutronError\": {\"type\": \"DuplicateSecurityGroupRuleInPost\", \"message\": \"Duplicate Security Group Rule in POST.\", \"detail\": \"\"}}"
    extensions.go:197: Attempting to delete security group rule: 3a3073ed-b9d9-40a9-b767-fb2ebf3325ec
    extensions.go:185: Attempting to delete security group: 992f1e0d-cbb2-45dc-9595-8fa3866d665a

I've rerun this too.

@stephenfin
Copy link
Contributor Author

stephenfin commented May 21, 2025

Weird: the designate dalmatian job failed to deploy due to a missing dependency, but I haven't touched that and the upstream branch is mostly unchanged 😕

...

I've rerun the job in case it was a once-off.

No such luck. I am investigating. I have also asked the ironic team about the persistent ironic failures, since it seems related to a recently-merged feature in their devstack plugin. I expect the messaging tests to fail until we fix it.

UPDATE: I've reproduced this locally on an Ubuntu 22.04 VM. This is not specific to this PR.

@EmilienM EmilienM merged commit 2813e74 into gophercloud:main May 22, 2025
59 of 64 checks passed
@EmilienM EmilienM deleted the randomise-tests branch May 22, 2025 12:06
@pierreprinetti
Copy link
Member

@stephenfin

The networking test failed because of a duplicate security group rule. This is likely because we use RandomInt to generate random port ranges and these probably overlapped. We might need to hardcode these.

PTAL: #3392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
edit:baremetal This PR updates baremetal code edit:baremetalintrospection This PR updates baremetalintrospection code edit:blockstorage This PR updates blockstorage code edit:common This PR updates common code edit:compute This PR updates compute code edit:container This PR updates container code edit:containerinfra This PR updates containerinfra code edit:db This PR updates db code edit:dns This PR updates dns code edit:gophercloud This PR updates common Gophercloud code edit:identity This PR updates identity code edit:image This PR updates image code edit:keymanager This PR updates keymanager code edit:loadbalancer This PR updates loadbalancer code edit:messaging This PR updates messaging code edit:networking This PR updates networking code edit:objectstorage This PR updates objectstorage code edit:openstack This PR updates common OpenStack code edit:orchestration This PR updates orchestration code edit:placement This PR updates placement code edit:sharedfilesystems This PR updates sharedfilesystems code edit:testinfra This PR updates testing infrastructure code edit:utils This PR updates utils code edit:workflow This PR updates workflow code semver:major Breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants