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

Remove stestr's grouping configuration #6399

Merged
merged 1 commit into from
May 12, 2021

Conversation

jorconnor
Copy link
Contributor

Removing the grouping regex in .stestr.conf should allow stestr to pack its test workers better, and therefore improve the speed of test execution. However, pre-existing test cases utilizing non-unique tempfiles began to fail after the configuration change. This commit modifies such tests to pass under these new conditions. This also allows the test suite to properly execute using pytest-xdist.

Fixed #6105

Summary

Per #6105 a few tests (TestGateMap and TestUserConfig) were failing when using pytest-xdist. Both tests were reliant on a hardcoded file name "temp.txt", which is the root source of the failures. This pull modifies both to use less brittle file buffers.

I also went ahead and removed the regex found in https://github.com/Qiskit/qiskit-terra/blob/master/.stestr.conf#L3 as discussed in the issue. After correcting the tests I have not seen any issues with the configuration change. I will adjust the merge request if any reviewers are uncomfortable removing it or if it fails in ci checks.

Details and comments

For TestGateMap:
I modified the test so that it utilizes io.BytesIO instead of needlessly writing to the problamatic temp file.

For TestUserConfig:
I moved the "string" configurations to their own personal files found in test/python/configurations. This might make it a bit harder to tell what the test is testing i.e. in the future devs will have to open the configuration file. However, this avoids the write to the problematic temp file and should create a less brittle test.

@jorconnor jorconnor requested review from nkanazawa1989, nonhermitian and a team as code owners May 11, 2021 21:15
@CLAassistant
Copy link

CLAassistant commented May 11, 2021

CLA assistant check
All committers have signed the CLA.

@javabster javabster added good first issue Good for newcomers type: qa Issues and PRs that relate to testing and code quality labels May 12, 2021
@mtreinish mtreinish removed the good first issue Good for newcomers label May 12, 2021
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Thanks a bunch for doing this, I think it's definitely a good step to move to method level parallelism for CI. I do wonder if we'll encounter issues with 2 test methods in a class conflicting with each other (even for just limited resources) but we can tackle that when the time comes.

I left a comment inline about a potential alternative approach for user config tests, I'm personally not a fan of the splitting the config for the tests out into separate files. Other than that it doesn't look .stestr.conf is actually modified in this PR, was your intent to remove the group_regex flag in this PR?

Comment on lines 25 to 28
current_dir = os.path.dirname(os.path.abspath(__file__))
test_name = str(self.id()).split(".")[-1]
file_path = os.path.join(current_dir, "configurations", test_name + ".conf")
self.config = user_config.UserConfig(file_path)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not super thrilled about this approach. Personally I find this kind of fragile to have to match the test name with a filename in a relative directory. Also as you mentioned it moves the configuration away from the test code which makes it harder to develop and debug tests here. I do wonder if there is an approach we can use that avoids shared state but also lets us create files.

What about something like:

def setUp(self):
    super().setUp()
    self.file_path = 'test_%s.conf' % uuid.uuid4()

and then leave tests as they were. That would ensure a unique file_name for each test. The only downside with that approach is there would need to be a cleanup in each test to delete the file for each test (but that was already done before).

Copy link
Contributor Author

@jorconnor jorconnor May 12, 2021

Choose a reason for hiding this comment

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

Yea I considered using a uuid to create a filename. My gut was sort of against it, but I do not really have any specific reasons for it. I think I just have a hesitation of writing files in a test unless it is necessary. If you are fine with the uuid then that is enough for me to get over it though.

@mtreinish mtreinish changed the title Removes stestrs grouping configuration. Removes stestr's grouping configuration May 12, 2021
@jorconnor jorconnor force-pushed the remote_stestr_grouping branch from 682019d to 5ae34b5 Compare May 12, 2021 13:42
Removing  the grouping regex in .stestr.conf should allow stestr to pack its test workers better, and therefore improve the speed of test execution. However, pre-existing test cases utilizing non-unique tempfiles began to fail after the configuration change. This commit modifies such tests to pass under these new conditions. This also allows the test suite to properly execute using pytest-xdist.

Fixed Qiskit#6105
@jorconnor jorconnor force-pushed the remote_stestr_grouping branch from 5ae34b5 to e80793e Compare May 12, 2021 13:46
@jorconnor
Copy link
Contributor Author

jorconnor commented May 12, 2021

My intent was to remove the group_regex. I think I may have backed it out when I was dealing with some merge conflicts... sorry that is a silly mistake. I've added it back to the merge.

@jorconnor jorconnor requested a review from mtreinish May 12, 2021 14:08
@mtreinish mtreinish changed the title Removes stestr's grouping configuration Remove stestr's grouping configuration May 12, 2021
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the quick update

@mergify mergify bot merged commit 5664ab4 into Qiskit:main May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: qa Issues and PRs that relate to testing and code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use unique filenames to allow test parallelization
4 participants