Skip to content

Commit

Permalink
Fix flaky GCS test
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcgibbon committed Nov 21, 2024
1 parent 96ea13e commit b46eb0f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
6 changes: 0 additions & 6 deletions lib/app_profiler/storage/google_cloud_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ def enqueue_upload(profile)
end
end

def reset_queue # for testing
init_queue
@process_queue_thread&.kill
@process_queue_thread = nil
end

private

def mutex
Expand Down
2 changes: 1 addition & 1 deletion test/app_profiler/middleware_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class MiddlewareTest < TestCase
assert(response[1]["X-Profile-Async"])
end
ensure
AppProfiler::Storage::GoogleCloudStorage.reset_queue # kill the background thread and reset the queue
reset_process_queue_thread # kill the background thread and reset the queue
AppProfiler.storage = old_storage
end

Expand Down
7 changes: 2 additions & 5 deletions test/app_profiler/storage/google_cloud_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class GoogleCloudStorageTest < AppProfiler::TestCase
TEST_BUCKET_NAME = "app-profile-test"
TEST_FILE_URL = "https://www.example.com/uploaded.json"

def teardown
GoogleCloudStorage.reset_queue
end
teardown(:reset_process_queue_thread)

test "upload file" do
profile = profile_from_stackprof
Expand Down Expand Up @@ -114,9 +112,8 @@ def teardown
end

test "process_queue_thread is alive after first upload" do
th = GoogleCloudStorage.instance_variable_get(:@process_queue_thread)
reset_process_queue_thread

refute(th&.alive?)
GoogleCloudStorage.enqueue_upload(profile_from_stackprof)
th = GoogleCloudStorage.instance_variable_get(:@process_queue_thread)
assert(th.alive?)
Expand Down
6 changes: 6 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,11 @@ def with_yarn_setup(app)
ensure
app.instance_variable_set(:@yarn_initialized, old_yarn_setup)
end

def reset_process_queue_thread
Storage::GoogleCloudStorage.send(:init_queue)
Storage::GoogleCloudStorage.instance_variable_get(:@process_queue_thread)&.kill
Storage::GoogleCloudStorage.instance_variable_set(:@process_queue_thread, nil)
end
end
end

0 comments on commit b46eb0f

Please sign in to comment.