Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson authored and mattBrzezinski committed Mar 20, 2023
1 parent ba7a65a commit c4741ba
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

BUCKET_NAME = "aws-jl-test-issues---" * _now_formatted()

# We try to be insensitive to the existence of other logging messages, so we test
# by counting the number of messages that meet some criteria
function log_is_retry(successful)
return record ->
record.level == Logging.Debug &&
haskey(record.kwargs, :retry) &&
record.kwargs[:retry] == successful
end

try
S3.create_bucket(BUCKET_NAME)

Expand Down Expand Up @@ -202,7 +211,7 @@ try
config = AWSConfig(; creds=nothing)

@testset "Fail 2 attempts then succeed" begin
logger = Test.TestLogger()
logger = Test.TestLogger(; min_level=Logging.Debug)
with_logger(logger) do
apply(_incomplete_patch(; data=data, num_attempts_to_fail=2)) do
retrieved = S3.get_object(bucket, key; aws_config=config)
Expand All @@ -212,8 +221,10 @@ try
end
end
logs = logger.logs
@test logs[1].level == Logging.Debug
@test logs[1].kwargs.retry
# Two successful retries
@test count(log_is_retry(true), logs) == 2
# No unsuccessful ones
@test count(log_is_retry(false), logs) == 0
end

@testset "Fail all 4 attempts then throw" begin
Expand All @@ -224,15 +235,23 @@ try
end
io = IOBuffer()

apply(_incomplete_patch(; data=data, num_attempts_to_fail=4)) do
params = Dict("response_stream" => io)
@test_throws err_t S3.get_object(bucket, key, params; aws_config=config)

seekstart(io)
retrieved = read(io)
@test length(retrieved) == n - 1
@test retrieved == data[1:(n - 1)]
logger = Test.TestLogger(; min_level=Logging.Debug)
with_logger(logger) do
apply(_incomplete_patch(; data=data, num_attempts_to_fail=4)) do
params = Dict("response_stream" => io)
@test_throws err_t S3.get_object(bucket, key, params; aws_config=config)

seekstart(io)
retrieved = read(io)
@test length(retrieved) == n - 1
@test retrieved == data[1:(n - 1)]
end
end
logs = logger.logs
# Three successful retries - from the inner retry loop
@test count(log_is_retry(true), logs) == 3
# One unsuccessful one - from the outer loop where we pass it on
@test count(log_is_retry(false), logs) == 1
end
end

Expand Down

0 comments on commit c4741ba

Please sign in to comment.