Skip to content

Fix race condition in test case envs dir deletion (#8438)#8440

Closed
inmantaci wants to merge 1 commit intoiso7from
merge-tool/8438/iso7
Closed

Fix race condition in test case envs dir deletion (#8438)#8440
inmantaci wants to merge 1 commit intoiso7from
merge-tool/8438/iso7

Conversation

@inmantaci
Copy link
Copy Markdown
Contributor

Pull request opened by the merge tool on behalf of #8438

…ories_on_server` test case. (PR #8438)

# Description

Fix race condition in `test_environment_delete_removes_env_directories_on_server` test case. The registration of the compile request happens asynchronously with respect to the `notify_change()` API call. So the `is_compiling()` API call can happen before the compile request is created or before the compilation has started.

```
02:45:43 __________ test_environment_delete_removes_env_directories_on_server ___________
02:45:43
02:45:43 server = <inmanta.server.protocol.Server object at 0x7f67cc481c50>
02:45:43 client = <inmanta.protocol.endpoints.Client object at 0x7f67cc786610>
02:45:43
02:45:43     async def test_environment_delete_removes_env_directories_on_server(
02:45:43         server,
02:45:43         client,
02:45:43     ) -> None:
02:45:43         """
02:45:43         Make sure the environment_delete endpoint deletes the environment directory on the server.
02:45:43         """
02:45:43         state_dir: Optional[str] = config.Config.get("config", "state-dir")
02:45:43         assert state_dir is not None
02:45:43         env_dir = py.path.local(state_dir).join("server", "environments")
02:45:43
02:45:43         result = await client.create_project("env-test")
02:45:43         assert result.code == 200
02:45:43         project_id = result.result["project"]["id"]
02:45:43
02:45:43         result = await client.create_environment(project_id=project_id, name="env1")
02:45:43         assert result.code == 200
02:45:43         env_id = result.result["environment"]["id"]
02:45:43
02:45:43         result: Result = await client.notify_change(env_id)
02:45:43         assert result.code == 200
02:45:43
02:45:43         async def wait_for_compile() -> bool:
02:45:43             result = await client.is_compiling(env_id)
02:45:43             return result.code == 204
02:45:43
02:45:43         await utils.retry_limited(wait_for_compile, 15)
02:45:43
02:45:43 >       assert os.path.exists(os.path.join(env_dir, env_id))
02:45:43 E       AssertionError: assert False
02:45:43 E        +  where False = <function exists at 0x7f680b8b7420>('/tmp/tmpmm37oya2/server/environments/a75c6da0-c84b-4ab7-b1d9-b661c109bc96')
02:45:43 E        +    where <function exists at 0x7f680b8b7420> = <module 'posixpath' (frozen)>.exists
02:45:43 E        +      where <module 'posixpath' (frozen)> = os.path
02:45:43 E        +    and   '/tmp/tmpmm37oya2/server/environments/a75c6da0-c84b-4ab7-b1d9-b661c109bc96' = <function join at 0x7f6809a305e0>(local('/tmp/tmpmm37oya2/server/environments'), 'a75c6da0-c84b-4ab7-b1d9-b661c109bc96')
02:45:43 E        +      where <function join at 0x7f6809a305e0> = <module 'posixpath' (frozen)>.join
02:45:43 E        +        where <module 'posixpath' (frozen)> = os.path
02:45:43
02:45:43 tests/server/test_compilerservice.py:1979: AssertionError
```

# Self Check

- [ ] ~~Attached issue to pull request~~
- [x] Changelog entry
- [x] Type annotations are present
- [x] Code is clear and sufficiently documented
- [x] No (preventable) type errors (check using make mypy or make mypy-diff)
- [x] Sufficient test cases (reproduces the bug/tests the requested feature)
- [x] Correct, in line with design
- [ ] ~~End user documentation is included or an issue is created for end-user documentation~~
- [ ] ~~If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)~~
@inmantaci inmantaci added the merge-tool-ready This ticket is ready to be merged in label Dec 4, 2024
@inmantaci
Copy link
Copy Markdown
Contributor Author

Merged into branches iso7 in e5acdec

@inmantaci inmantaci closed this Dec 4, 2024
@inmantaci inmantaci deleted the merge-tool/8438/iso7 branch December 4, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-tool-ready This ticket is ready to be merged in

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants