-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1362666: improve random string generation (#2034)
- Loading branch information
1 parent
2b44cd3
commit 050a1ac
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,37 @@ | ||
# | ||
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. | ||
# | ||
|
||
import concurrent.futures | ||
import random | ||
|
||
import pytest | ||
|
||
try: | ||
from snowflake.connector.util_text import random_string | ||
except ImportError: | ||
pass | ||
|
||
pytestmark = pytest.mark.skipolddriver # old test driver tests won't run this module | ||
|
||
|
||
def test_random_string_generation_with_same_global_seed(): | ||
random.seed(42) | ||
random_string1 = random_string() | ||
random.seed(42) | ||
random_string2 = random_string() | ||
assert ( | ||
isinstance(random_string1, str) | ||
and isinstance(random_string2, str) | ||
and random_string1 != random_string2 | ||
) | ||
|
||
def get_random_string(): | ||
random.seed(42) | ||
return random_string() | ||
|
||
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: | ||
# Submit tasks to the pool and get future objects | ||
futures = [executor.submit(get_random_string) for _ in range(5)] | ||
res = [f.result() for f in futures] | ||
assert len(set(res)) == 5 # no duplicate string |