| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b1f49f7 commit 0544208
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,8 @@ | |||
| 14 | 14 | from google.cloud.spanner_v1 import Client | |
| 15 | 15 | ||
| 16 | 16 | REGION = "regional-us-central1" | |
| 17 | + WORKER_INDEX = int(os.getenv("DJANGO_WORKER_INDEX", 0)) | ||
| 18 | + WORKER_COUNT = int(os.getenv("DJANGO_WORKER_COUNT", 1)) | ||
| 17 | 19 | ||
| 18 | 20 | ||
| 19 | 21 | class TestInstance: | |
@@ -27,13 +29,11 @@ def __enter__(self): | |||
| 27 | 29 | ||
| 28 | 30 | config = f"{client.project_name}/instanceConfigs/{REGION}" | |
| 29 | 31 | ||
| 30 | - name = "spanner-django-test-{}".format(str(int(time.time()))) | ||
| 32 | + name = "sp-dj-test-{}-{}".format( | ||
| 33 | + str(WORKER_INDEX), str(int(time.time())) | ||
| 34 | + ) | ||
| 31 | 35 | ||
| 32 | 36 | self._instance = client.instance(name, config) | |
| 33 | - if self._instance.exists(): | ||
| 34 | - # If test instance already exists first delete it and then create. | ||
| 35 | - self._instance.delete() | ||
| 36 | - created_op.result(120) # block until completion | ||
| 37 | 37 | created_op = self._instance.create() | |
| 38 | 38 | created_op.result(120) # block until completion | |
| 39 | 39 | return name | |
@@ -42,24 +42,21 @@ def __exit__(self, exc, exc_value, traceback): | |||
| 42 | 42 | self._instance.delete() | |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | - worker_index = int(os.getenv("DJANGO_WORKER_INDEX", 0)) | ||
| 46 | - worker_count = int(os.getenv("DJANGO_WORKER_COUNT", 1)) | ||
| 47 | - | ||
| 48 | - if worker_index >= worker_count: | ||
| 45 | + if WORKER_INDEX >= WORKER_COUNT: | ||
| 49 | 46 | print( | |
| 50 | - "worker_index ({wi}) > worker_count ({wc})".format( | ||
| 51 | - wi=worker_index, | ||
| 52 | - wc=worker_count, | ||
| 47 | + "WORKER_INDEX ({wi}) > WORKER_COUNT ({wc})".format( | ||
| 48 | + wi=WORKER_INDEX, | ||
| 49 | + wc=WORKER_COUNT, | ||
| 53 | 50 | ) | |
| 54 | 51 | ) | |
| 55 | 52 | exit() | |
| 56 | 53 | ||
| 57 | 54 | with open("django_test_apps.txt", "r") as file: | |
| 58 | 55 | all_apps = file.read().split("\n") | |
| 59 | 56 | ||
| 60 | - apps_per_worker = math.ceil(len(all_apps) / worker_count) | ||
| 57 | + apps_per_worker = math.ceil(len(all_apps) / WORKER_COUNT) | ||
| 61 | 58 | ||
| 62 | - start_index = min(worker_index * apps_per_worker, len(all_apps)) | ||
| 59 | + start_index = min(WORKER_INDEX * apps_per_worker, len(all_apps)) | ||
| 63 | 60 | end_index = min(start_index + apps_per_worker, len(all_apps)) | |
| 64 | 61 | ||
| 65 | 62 | test_apps = all_apps[start_index:end_index] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments