|
1 | 1 | from pathlib import Path
|
2 | 2 |
|
3 | 3 | import pytest
|
| 4 | +import time |
4 | 5 | from dvc.env import DVC_EXP_GIT_REMOTE
|
5 | 6 | from dvc_studio_client import DEFAULT_STUDIO_URL
|
6 | 7 | from dvc_studio_client.env import DVC_STUDIO_REPO_URL, DVC_STUDIO_TOKEN
|
@@ -186,6 +187,30 @@ def test_post_to_studio_done_only_once(tmp_dir, mocked_dvc_repo, mocked_studio_p
|
186 | 187 | assert expected_done_calls == actual_done_calls
|
187 | 188 |
|
188 | 189 |
|
| 190 | +def test_studio_updates_posted_on_end(tmp_path, mocked_dvc_repo, mocked_studio_post): |
| 191 | + mocked_post, valid_response = mocked_studio_post |
| 192 | + metrics_file = tmp_path / "metrics.json" |
| 193 | + metrics_content = "metrics" |
| 194 | + |
| 195 | + def long_post(*args, **kwargs): |
| 196 | + # in case of `data` `long_post` should be called from a separate thread, |
| 197 | + # meanwhile main thread go forward without slowing down, so if there is no |
| 198 | + # some kind of wait in the Live main thread, then it will complete before |
| 199 | + # we even can have a chance to write the file below |
| 200 | + if kwargs["json"]["type"] == "data": |
| 201 | + time.sleep(1) |
| 202 | + metrics_file.write_text(metrics_content) |
| 203 | + |
| 204 | + return valid_response |
| 205 | + |
| 206 | + mocked_post.side_effect = long_post |
| 207 | + |
| 208 | + with Live() as live: |
| 209 | + live.log_metric("foo", 1) |
| 210 | + |
| 211 | + assert metrics_file.read_text() == metrics_content |
| 212 | + |
| 213 | + |
189 | 214 | @pytest.mark.studio()
|
190 | 215 | def test_post_to_studio_skip_start_and_done_on_env_var(
|
191 | 216 | tmp_dir, mocked_dvc_repo, mocked_studio_post, monkeypatch
|
|
0 commit comments