Skip to content

Commit

Permalink
Add retries to tests depending on HTTP (#10815)
Browse files Browse the repository at this point in the history
- Continuation of #9652 - apparently some tests that depend on HTTP requests were missed then.
- Closes #10742
  • Loading branch information
radeusgd authored Aug 14, 2024
1 parent f8eb922 commit 09f3a0b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
25 changes: 12 additions & 13 deletions test/Base_Tests/src/Network/URI_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ add_specs suite_builder =
uri.fragment.should_equal Nothing

# We rely on the http-test-helper for these tests, to ensure that the encoding is indeed correctly interpreted by a real-life server:
group_builder.specify "should correctly handle various characters within the key and value of arguments" pending=pending_has_url <|
group_builder.specify "should correctly handle various characters within the key and value of arguments" pending=pending_has_url <| Test.with_retries <|
base_uri = URI.parse base_url+"get"

uri1 = base_uri . add_query_argument "a" "b"
Expand Down Expand Up @@ -166,7 +166,7 @@ add_specs suite_builder =
r4 = uri4.fetch
decode_query_params r4 . should_equal [["p+r", "b c"], ["p r", "b c"], ["🚀", "🚧"], ["śnieżnobiałą", "łąkę"], [s2, "zzz"]]

group_builder.specify "may allow duplicate keys in query parameters" pending=pending_has_url <|
group_builder.specify "may allow duplicate keys in query parameters" pending=pending_has_url <| Test.with_retries <|
uri = URI.parse base_url+"get"
. add_query_argument "a" "b"
. add_query_argument "a" "c"
Expand Down Expand Up @@ -220,7 +220,7 @@ add_specs suite_builder =
uri5 = uri4 / "b"
uri5.path . should_equal "/get/a//b"

group_builder.specify "should allow various characters in the path" pending=pending_has_url <|
group_builder.specify "should allow various characters in the path" pending=pending_has_url <| Test.with_retries <|
uri0 = URI.parse base_url+"get"
uri1 = uri0 / "a b c" / "d+e" / "f%20g" / "ś🚧:@"

Expand Down Expand Up @@ -291,9 +291,9 @@ add_specs suite_builder =

cloud_setup = Cloud_Tests_Setup.prepare

group_builder.specify "will not convert back to URI if secrets are present in the query arguments" pending=cloud_setup.pending <|
group_builder.specify "will not convert back to URI if secrets are present in the query arguments" pending=cloud_setup.pending <| Test.with_retries <|
cloud_setup.with_prepared_environment <|
secret1 = Enso_Secret.create "my_test_secret-uri-1" "My Value"
secret1 = Enso_Secret.create "my_test_secret-uri-1-"+Random.uuid "My Value"
secret1.should_succeed
Panic.with_finalizer secret1.delete <|
uri = URI.from "https://example.com/"
Expand All @@ -304,13 +304,13 @@ add_specs suite_builder =
uri.to_java_uri . should_fail_with Enso_Secret_Error
uri.raw_query . should_fail_with Enso_Secret_Error

group_builder.specify "should allow to use secrets in query arguments, containing all kinds of various characters" pending=cloud_setup.httpbin_pending <|
group_builder.specify "should allow to use secrets in query arguments, containing all kinds of various characters" pending=cloud_setup.httpbin_pending <| Test.with_retries <|
cloud_setup.with_prepared_environment <|
secret1 = Enso_Secret.create "my_test_secret-uri-4" "My Very Secret Value"
secret1 = Enso_Secret.create "my_test_secret-uri-4-"+Random.uuid "My Very Secret Value"
secret1.should_succeed
Panic.with_finalizer secret1.delete <|
s2 = "Another Secret Value containing Emoji 😊❤️ and ąęś AND [a=b]:[b=c][d=e]++++!?&->#...__(){}@///\\\|%%%100*^, ]]] ==> <br>a"
secret2 = Enso_Secret.create "my_test_secret-uri-5" s2
secret2 = Enso_Secret.create "my_test_secret-uri-5"+Random.uuid s2
secret2.should_succeed
Panic.with_finalizer secret2.delete <|
uri = (cloud_setup.httpbin_secure_uri / "get")
Expand All @@ -321,13 +321,12 @@ add_specs suite_builder =
uri.to_text . should_equal (cloud_setup.httpbin_secure_uri.to_text + "get?arg1=__SECRET__&arg2=plain+value&arg3=__SECRET__")
uri.raw_query . should_fail_with Enso_Secret_Error

Test.with_retries <|
response = cloud_setup.httpbin_secure_client.request (Request.get uri)
decode_query_params response.decode_as_json . should_equal [["arg1", "My Very Secret Value"], ["arg2", "plain value"], ["arg3", s2]]
response = cloud_setup.httpbin_secure_client.request (Request.get uri)
decode_query_params response.decode_as_json . should_equal [["arg1", "My Very Secret Value"], ["arg2", "plain value"], ["arg3", s2]]

group_builder.specify "does not allow secrets in non-https requests" pending=cloud_setup.pending <|
group_builder.specify "does not allow secrets in non-https requests" pending=cloud_setup.pending <| Test.with_retries <|
cloud_setup.with_prepared_environment <|
secret1 = Enso_Secret.create "my_test_secret-uri-8" "My Value"
secret1 = Enso_Secret.create "my_test_secret-uri-8-"+Random.uuid "My Value"
secret1.should_succeed
Panic.with_finalizer secret1.delete <|
uri1 = URI.from "http://example.com/"
Expand Down
2 changes: 1 addition & 1 deletion test/Table_Tests/src/Database/Postgres_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ add_data_link_specs suite_builder =
r.should_fail_with Illegal_Argument
r.catch.to_display_text . should_contain "The Postgres Data Link does not support writing"

group_builder.specify "will fail with a clear message if trying to download a Database data link" pending=Http_Test_Setup.pending_has_url <|
group_builder.specify "will fail with a clear message if trying to download a Database data link" pending=Http_Test_Setup.pending_has_url <| Test.with_retries <|
url = Http_Test_Setup.base_url_with_slash+"testfiles/some-postgres.datalink"
target_file = enso_project.data / "transient" / "some-postgres-target"
target_file.delete_if_exists
Expand Down
16 changes: 8 additions & 8 deletions test/Table_Tests/src/IO/Data_Link_Formats_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,45 @@ main filter=Nothing =

add_specs suite_builder = suite_builder.group "parsing Table formats in DataLinks" pending=pending_has_url group_builder->
data_link_root = enso_project.data / "datalinks"
group_builder.specify "parsing Delimited without quotes" <|
group_builder.specify "parsing Delimited without quotes" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-delimited-ignore-quote.datalink")
t = data_link_file.read
t.should_equal (Table.from_rows ["Column 1", "Column 2"] [['{"hello":', '"world"}']])

group_builder.specify "parsing Delimited with custom delimiter quotes" <|
group_builder.specify "parsing Delimited with custom delimiter quotes" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-delimited-custom-quote.datalink")
t = data_link_file.read
weird_txt = "x'z" + '""w'
# The A column remains a text column because of being quoted
t.should_equal (Table.new [["A", ["1", "3"]], ["B", [weird_txt, "y"]]])

group_builder.specify "overriding the custom format in Delimited datalink" <|
group_builder.specify "overriding the custom format in Delimited datalink" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-delimited-ignore-quote.datalink")
r = data_link_file.read ..Plain_Text
r.should_be_a Text
r.trim.should_equal '{"hello": "world"}'

group_builder.specify "parsing Excel_Format.Workbook" <|
group_builder.specify "parsing Excel_Format.Workbook" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-excel-workbook.datalink")

workbook = data_link_file.read
Panic.with_finalizer workbook.close <|
workbook.should_be_a Excel_Workbook
workbook.sheet_names . should_equal ["MyTestSheet"]

group_builder.specify "parsing Excel_Format.Sheet" <|
group_builder.specify "parsing Excel_Format.Sheet" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-excel-sheet.datalink")

table = data_link_file.read
table . should_equal (Table.from_rows ["A", "B"] [[1, 'x'], [3, 'y']])

group_builder.specify "parsing Excel_Format.Range" <|
group_builder.specify "parsing Excel_Format.Range" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-excel-range.datalink")

table = data_link_file.read
table . should_equal (Table.from_rows ["A", "B"] [[3, 'y']])

group_builder.specify "overriding Excel format" <|
group_builder.specify "overriding Excel format" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-excel-workbook.datalink")

table = data_link_file.read (..Range "MyTestSheet!A1:B1")
Expand All @@ -66,7 +66,7 @@ add_specs suite_builder = suite_builder.group "parsing Table formats in DataLink
bytes = data_link_file.read_bytes
bytes.should_be_a Vector

group_builder.specify "reading a datalink as a stream" <|
group_builder.specify "reading a datalink as a stream" <| Test.with_retries <|
data_link_file = replace_url_in_data_link (data_link_root / "example-http-format-excel-range.datalink")

r1 = data_link_file.with_input_stream [File_Access.Read] input_stream->
Expand Down

0 comments on commit 09f3a0b

Please sign in to comment.