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

Fix flaky `./pants idea-plugin` when using Python 3 by properly using ConsoleTask interface #7460

Merged
merged 3 commits into from Mar 30, 2019

Conversation

Projects
None yet
3 participants
@Eric-Arellano
Copy link
Contributor

commented Mar 29, 2019

Problem

The Idea plugin integration tests would frequently flake with Python 3.

This appears to be because the task is a ConsoleTask, but it overrides execute() when it is instead expected to override console_output(). With this override, we would no longer call self._outstream.flush(), so the tests would sometimes complain that there was no entry in the --output-file, as the change would not always be persisted. It makes sense that this did not start flaking until Python 3, because IO streams changed their behavior in Python 3.

Refer to ConsoleTask for everything we need to do to properly output to the console and files:

def execute(self):
with self._guard_sigpipe():
try:
targets = self.context.targets()
for value in self.console_output(targets) or tuple():
self._outstream.write(value.encode('utf-8'))
self._outstream.write(self._console_separator.encode('utf-8'))
finally:
self._outstream.flush()
if self.get_options().output_file:
self._outstream.close()

Will close #7150.

Solution

No longer override execute() and instead move the logic into console_output().

Result

The tests no longer flake.

This was confirmed locally by creating the script untilfail:

#!/bin/bash

while $@; do :; done

Then running ./untilfail ./pants clean-all test.pytest tests/python/pants_test/backend/project_info/tasks:idea_plugin_integration -- -k test_idea_plugin_single_target for 10 minutes on both macOS and Ubuntu without fail.

Eric-Arellano added some commits Mar 29, 2019

@Eric-Arellano Eric-Arellano changed the title WIP: Unblacklist Idea plugin generation test that no longer flakes with Python 3 WIP: Fix flaky `./pants idea-plugin` when using Python 3 by properly using ConsoleTask interface Mar 30, 2019

@Eric-Arellano Eric-Arellano changed the title WIP: Fix flaky `./pants idea-plugin` when using Python 3 by properly using ConsoleTask interface Fix flaky `./pants idea-plugin` when using Python 3 by properly using ConsoleTask interface Mar 30, 2019

@stuhood
Copy link
Member

left a comment

Nice find!

@Eric-Arellano Eric-Arellano merged commit 42937b0 into pantsbuild:master Mar 30, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@Eric-Arellano Eric-Arellano deleted the Eric-Arellano:flaky-idea-test branch Mar 30, 2019

stuhood added a commit that referenced this pull request Apr 1, 2019

Fix flaky `./pants idea-plugin` when using Python 3 by properly using…
… ConsoleTask interface (#7460)

### Problem
The Idea plugin integration tests would frequently flake with Python 3.

This appears to be because the task is a `ConsoleTask`, but it overrides `execute()` when it is instead expected to override `console_output()`. With this override, we would no longer call `self._outstream.flush()`, so the tests would sometimes complain that there was no entry in the `--output-file`, as the change would not always be persisted. It makes sense that this did not start flaking until Python 3, because IO streams changed their behavior in Python 3.

Refer to `ConsoleTask` for everything we need to do to properly output to the console and files: https://github.com/pantsbuild/pants/blob/e620a9e862a245088bc5b477aed2b87e2bc6a307/src/python/pants/task/console_task.py#L52-L62

Will close #7150.

### Solution
No longer override `execute()` and instead move the logic into `console_output()`.

### Result
The tests no longer flake.

This was confirmed locally by creating the script `untilfail`:

```bash
#!/bin/bash

while $@; do :; done
```

Then running `./untilfail ./pants clean-all test.pytest tests/python/pants_test/backend/project_info/tasks:idea_plugin_integration -- -k test_idea_plugin_single_target` for 10 minutes on both macOS and Ubuntu without fail.

@stuhood stuhood referenced this pull request Apr 3, 2019

Merged

Enable pantsd in Travis #7440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.