Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0544208

Browse filesBrowse files
authored
fix: remove delete of instance if it already exists, as it might be in use by another test (googleapis#641)
* test: fix run testing worker code to reduce the chance of same instance id being used by different workers * fix: remove delete of instance if it already exists, as it might be in use by another test
1 parent b1f49f7 commit 0544208
Copy full SHA for 0544208

File tree

Expand file treeCollapse file tree

1 file changed

+11
-14
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-14
lines changed

‎run_testing_worker.py

Copy file name to clipboardExpand all lines: run_testing_worker.py
+11-14Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from google.cloud.spanner_v1 import Client
1515

1616
REGION = "regional-us-central1"
17+
WORKER_INDEX = int(os.getenv("DJANGO_WORKER_INDEX", 0))
18+
WORKER_COUNT = int(os.getenv("DJANGO_WORKER_COUNT", 1))
1719

1820

1921
class TestInstance:
@@ -27,13 +29,11 @@ def __enter__(self):
2729

2830
config = f"{client.project_name}/instanceConfigs/{REGION}"
2931

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+
)
3135

3236
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
3737
created_op = self._instance.create()
3838
created_op.result(120) # block until completion
3939
return name
@@ -42,24 +42,21 @@ def __exit__(self, exc, exc_value, traceback):
4242
self._instance.delete()
4343

4444

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:
4946
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,
5350
)
5451
)
5552
exit()
5653

5754
with open("django_test_apps.txt", "r") as file:
5855
all_apps = file.read().split("\n")
5956

60-
apps_per_worker = math.ceil(len(all_apps) / worker_count)
57+
apps_per_worker = math.ceil(len(all_apps) / WORKER_COUNT)
6158

62-
start_index = min(worker_index * apps_per_worker, len(all_apps))
59+
start_index = min(WORKER_INDEX * apps_per_worker, len(all_apps))
6360
end_index = min(start_index + apps_per_worker, len(all_apps))
6461

6562
test_apps = all_apps[start_index:end_index]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.