-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Add support for system cache runtime #352
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
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6d25a31
Init before day break
schloerke 739752a
Integrate `System` into `Client`
schloerke 571f8f5
Add `.system.caches.runtime` classes with `.destroy()` methods
schloerke f22f196
unit and integration testing
schloerke 6f5c3e3
Only test caches length when connect versions >= 2023.05.0
schloerke 38a5c5d
Fix skip logic location
schloerke 00bdda6
Update test_system.py
schloerke 369d752
Only assert cache size on >= 2024.05.0
schloerke 38c45cc
Return None when using `dry_run=True`
schloerke 2210622
Reorganize integration test. Remove all caches at end
schloerke 08caf8d
Clean up imports
schloerke edf0675
Use client to retrieve path
schloerke a6e06f9
Remove check for `caches` key
schloerke 3f317c5
Remove `SystemCaches.destroy(SystemCache)` support as `SystemCache.de…
schloerke 997ec2c
merge main
schloerke 81d710f
Add comment
schloerke cd8a582
If there are no jobs, try again
schloerke 2133a30
remove wait for deployment job code
schloerke d40657c
lint
schloerke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import time | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from packaging import version | ||
|
|
||
| from posit.connect import Client | ||
| from posit.connect.system import SystemRuntimeCache | ||
| from posit.connect.tasks import Task | ||
|
|
||
| from . import CONNECT_VERSION | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| # Added to the v2023.05.0 milestone | ||
| # https://github.com/rstudio/connect/pull/23148 | ||
| CONNECT_VERSION < version.parse("2023.05.0"), | ||
| reason="Cache runtimes not implemented", | ||
| ) | ||
| class TestSystem: | ||
| @classmethod | ||
| def setup_class(cls): | ||
| cls.client = Client() | ||
| assert cls.client.content.count() == 0 | ||
| cls.content_item = cls.client.content.create(name="Content_A") | ||
|
|
||
| # Copied from from integration/tests/posit/connect/test_packages.py | ||
| def _deploy_python_bundle(self): | ||
| path = Path("../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz") | ||
| path = (Path(__file__).parent / path).resolve() | ||
| bundle = self.content_item.bundles.create(str(path)) | ||
| task = bundle.deploy() | ||
| task.wait_for() | ||
|
|
||
| def _remove_all_caches(self): | ||
| caches: list[SystemRuntimeCache] = self.client.system.caches.runtime.find() | ||
| for cache in caches: | ||
| assert isinstance(cache, SystemRuntimeCache) | ||
| none_val = cache.destroy(dry_run=True) | ||
| assert none_val is None | ||
| task: Task = cache.destroy() | ||
| assert isinstance(task, Task) | ||
| task.wait_for() | ||
| assert len(self.client.system.caches.runtime.find()) == 0 | ||
|
|
||
| def _wait_for_cache_jobs(self): | ||
| start_time = time.time() | ||
| continue_while = True | ||
| while continue_while: | ||
| now_time = time.time() | ||
| if now_time - start_time > 30: | ||
| raise TimeoutError("Timeout while waiting for cache to deploy") | ||
|
|
||
| jobs = self.content_item.jobs.fetch() | ||
| for job in jobs: | ||
| if str(job["status"]) == "0": | ||
| # Stop for loop and restart while loop | ||
| break | ||
| else: | ||
| # Only executed if the for loop did NOT break | ||
|
|
||
| # Break the while loop | ||
| continue_while = False | ||
|
|
||
| @classmethod | ||
| def teardown_class(cls): | ||
| cls.content_item.delete() | ||
| assert cls.client.content.count() == 0 | ||
|
|
||
| def test_runtime_caches(self): | ||
| # Get current caches | ||
| caches: list[SystemRuntimeCache] = self.client.system.caches.runtime.find() | ||
| assert isinstance(caches, list) | ||
|
|
||
| # Remove all caches | ||
| self._remove_all_caches() | ||
|
|
||
| # Deploy a new cache | ||
| self._deploy_python_bundle() | ||
|
|
||
| # Wait for the cache jobs to finish | ||
| self._wait_for_cache_jobs() | ||
|
|
||
| # Check if the cache is deployed | ||
| caches = self.client.system.caches.runtime.find() | ||
|
|
||
| # Caches only added in Connect versions >= 2024.05.0 | ||
| if CONNECT_VERSION >= version.parse("2024.05.0"): | ||
schloerke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert len(caches) > 0 | ||
|
|
||
| # Remove all caches | ||
| self._remove_all_caches() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.