|
7 | 7 | import os |
8 | 8 |
|
9 | 9 | import pytest |
| 10 | +import threading |
| 11 | +import queue |
10 | 12 |
|
11 | 13 | import snowflake.connector |
12 | 14 | from snowflake.connector import ( |
@@ -467,7 +469,7 @@ def test_eu_connection(tmpdir): |
467 | 469 | ) |
468 | 470 |
|
469 | 471 |
|
470 | | -@pytest.mark.timeout(15) |
| 472 | +#@pytest.mark.timeout(15) |
471 | 473 | def test_us_west_connection(tmpdir): |
472 | 474 | """ |
473 | 475 | region='us-west-2' indicates no region is included in the hostname, i.e., |
@@ -565,3 +567,71 @@ def test_privatelink_ocsp_url_creation(): |
565 | 567 | assert ocsp_cache_server == \ |
566 | 568 | "http://ocsp.testaccount.us-east-1.privatelink.snowflakecomputing.com/ocsp_response_cache.json" |
567 | 569 |
|
| 570 | + |
| 571 | +def test_privatelink_ocsp_url_multithreaded(): |
| 572 | + bucket = queue.Queue() |
| 573 | + |
| 574 | + hostname = "testaccount.us-east-1.privatelink.snowflakecomputing.com" |
| 575 | + expectation = "http://ocsp.testaccount.us-east-1.privatelink.snowflakecomputing.com/ocsp_response_cache.json" |
| 576 | + thread_obj = [] |
| 577 | + for i in range(15): |
| 578 | + thread_obj.append(ExecPrivatelinkThread(bucket, hostname, expectation, CLIENT_NAME)) |
| 579 | + |
| 580 | + for i in range(15): |
| 581 | + thread_obj[i].start() |
| 582 | + |
| 583 | + fail_flag = False |
| 584 | + for i in range(15): |
| 585 | + thread_obj[i].join() |
| 586 | + exc = bucket.get(block=False) |
| 587 | + if exc != 'Success' and not fail_flag: |
| 588 | + fail_flag = True |
| 589 | + |
| 590 | + if fail_flag: |
| 591 | + assert False, "OCSP URL was set incorrectly" |
| 592 | + |
| 593 | + if os.getenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL", None) is not None: |
| 594 | + del os.environ["SF_OCSP_RESPONSE_CACHE_SERVER_URL"] |
| 595 | + |
| 596 | + |
| 597 | +def test_privatelink_ocsp_url_multithreaded_snowsql(): |
| 598 | + bucket = queue.Queue() |
| 599 | + |
| 600 | + hostname = "testaccount.us-east-1.privatelink.snowflakecomputing.com" |
| 601 | + expectation = "http://ocsp.us-east-1.privatelink.snowflakecomputing.com/ocsp_response_cache.json" |
| 602 | + thread_obj = [] |
| 603 | + for i in range(15): |
| 604 | + thread_obj.append(ExecPrivatelinkThread(bucket, hostname, expectation, APPLICATION_SNOWSQL)) |
| 605 | + |
| 606 | + for i in range(15): |
| 607 | + thread_obj[i].start() |
| 608 | + |
| 609 | + fail_flag = False |
| 610 | + for i in range(15): |
| 611 | + thread_obj[i].join() |
| 612 | + exc = bucket.get(block=False) |
| 613 | + if exc != 'Success' and not fail_flag: |
| 614 | + fail_flag = True |
| 615 | + |
| 616 | + if fail_flag: |
| 617 | + assert False, "OCSP URL was set incorrectly" |
| 618 | + |
| 619 | + |
| 620 | +class ExecPrivatelinkThread(threading.Thread): |
| 621 | + |
| 622 | + def __init__(self, bucket, hostname, expectation, client_name): |
| 623 | + threading.Thread.__init__(self) |
| 624 | + self.bucket = bucket |
| 625 | + self.hostname = hostname |
| 626 | + self.expectation = expectation |
| 627 | + self.client_name = client_name |
| 628 | + |
| 629 | + def run(self): |
| 630 | + SnowflakeConnection.setup_ocsp_privatelink(self.client_name, self.hostname) |
| 631 | + ocsp_cache_server = os.getenv("SF_OCSP_RESPONSE_CACHE_SERVER_URL", None) |
| 632 | + if ocsp_cache_server is not None and ocsp_cache_server !=\ |
| 633 | + self.expectation: |
| 634 | + print("Got {0} Expected {1}".format(ocsp_cache_server, self.expectation)) |
| 635 | + self.bucket.put("Fail") |
| 636 | + else: |
| 637 | + self.bucket.put("Success") |
0 commit comments