fuck should i throw this project out? home@Desktop:~/p/g/n/elixir_ml/foundation/test$ grep -ir sleep * foundation/services/service_behaviour_test.exs: Process.sleep(100) foundation/services/service_behaviour_test.exs: Process.sleep(150) foundation/services/service_behaviour_test.exs: Process.sleep(150) foundation/services/service_behaviour_test.exs: Process.sleep(150) foundation/services/service_behaviour_test.exs: Process.sleep(150) foundation/services/service_behaviour_test.exs: Process.sleep(150) foundation/services/service_behaviour_test.exs: Process.sleep(150) foundation/services/service_behaviour_test.exs: Process.sleep(10) foundation/process_registry/properties.ex: Process.sleep(10) foundation/process_registry/properties.ex: live_pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: pid = spawn(fn -> Process.sleep(100) end) foundation/process_registry/properties.ex: Process.sleep(200) foundation/process_registry/properties.ex: new_pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/properties.ex: spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry/backend/enhanced_ets_test.exs: agent_pid = spawn(fn -> Process.sleep(1000) end) foundation/process_registry/backend/enhanced_ets_test.exs: agent_pid = spawn(fn -> Process.sleep(1000) end) foundation/process_registry/backend/enhanced_ets_test.exs: agent_pid = spawn(fn -> Process.sleep(5000) end) foundation/process_registry/backend/enhanced_ets_test.exs: agent_pid = spawn(fn -> Process.sleep(2000) end) foundation/process_registry/backend/enhanced_ets_test.exs: agent_pid = spawn(fn -> Process.sleep(100) end) foundation/process_registry/backend/enhanced_ets_test.exs: agent_pid = spawn(fn -> Process.sleep(1000) end) foundation/process_registry/backend/enhanced_ets_test.exs: agent_pid = spawn(fn -> Process.sleep(1000) end) foundation/process_registry_optimizations_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: Process.sleep(10) foundation/process_registry_optimizations_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: Process.sleep(10) foundation/process_registry_optimizations_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: existing_pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: {test_namespace, :new_service_1, spawn(fn -> Process.sleep(:infinity) end), %{type: :new}}, foundation/process_registry_optimizations_test.exs: {test_namespace, :conflicting_service, spawn(fn -> Process.sleep(:infinity) end), foundation/process_registry_optimizations_test.exs: {test_namespace, :new_service_2, spawn(fn -> Process.sleep(:infinity) end), %{type: :new}} foundation/process_registry_optimizations_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: pid1 = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: pid2 = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_optimizations_test.exs: Process.sleep(10) foundation/process_registry_performance_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_performance_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_performance_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_performance_test.exs: spawn(fn -> Process.sleep(:infinity) end), foundation/process_registry_performance_test.exs: pid = spawn(fn -> Process.sleep(:infinity) end) foundation/process_registry_performance_test.exs: Process.sleep(10) integration/cross_service_integration_test.exs: Process.sleep(200) integration/cross_service_integration_test.exs: Process.sleep(10) integration/cross_service_integration_test.exs: Process.sleep(50) integration/cross_service_integration_test.exs: Process.sleep(50) integration/cross_service_integration_test.exs: Process.sleep(50) integration/cross_service_integration_test.exs: Process.sleep(100) integration/cross_service_integration_test.exs: Process.sleep(100) integration/cross_service_integration_test.exs: Process.sleep(100) integration/cross_service_integration_test.exs: Process.sleep(100) integration/cross_service_integration_test.exs: Process.sleep(100) integration/cross_service_integration_test.exs: Process.sleep(200) integration/foundation/config_events_telemetry_test.exs: Process.sleep(50) integration/foundation/config_events_telemetry_test.exs: Process.sleep(100) integration/foundation/config_events_telemetry_test.exs: Process.sleep(50) integration/foundation/config_events_telemetry_test.exs: Process.sleep(50) integration/foundation/config_events_telemetry_test.exs: Process.sleep(100) integration/foundation/config_events_telemetry_test.exs: Process.sleep(50) integration/foundation/config_events_telemetry_test.exs: Process.sleep(200) integration/foundation/service_lifecycle_test.exs: Process.sleep(150) integration/foundation/service_lifecycle_test.exs: Process.sleep(200) integration/foundation/service_lifecycle_test.exs: Process.sleep(200) integration/foundation/service_lifecycle_test.exs: Process.sleep(50) integration/foundation/service_lifecycle_test.exs: Process.sleep(50) integration/foundation/service_lifecycle_test.exs: Process.sleep(200) integration/foundation/service_lifecycle_test.exs: Process.sleep(50) integration/foundation/service_lifecycle_test.exs: Process.sleep(100) integration/foundation/service_lifecycle_test.exs: Process.sleep(100) integration/foundation/service_lifecycle_test.exs: Process.sleep(200) integration/foundation/service_lifecycle_test.exs: Process.sleep(200) integration/foundation/service_lifecycle_test.exs: Process.sleep(100) integration/foundation/service_lifecycle_test.exs: Process.sleep(200) integration/foundation/service_lifecycle_test.exs: Process.sleep(100) integration/foundation/service_lifecycle_test.exs: Process.sleep(100) integration/foundation/service_lifecycle_test.exs: Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(10) # Small delay integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(1100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(200) integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(200) integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(50) integration/foundation/service_lifecycle_test.exs: # Process.sleep(100) integration/foundation/service_lifecycle_test.exs: # Process.sleep(1) integration/foundation/service_lifecycle_test.exs: # Process.sleep(10) integration/foundation/service_lifecycle_test.exs: Process.sleep(50 * attempt) integration/foundation/service_lifecycle_test.exs: Process.sleep(100) integration/data_consistency_integration_test.exs: Process.sleep(100) integration/data_consistency_integration_test.exs: Process.sleep(100) integration/data_consistency_integration_test.exs: Process.sleep(100) integration/data_consistency_integration_test.exs: Process.sleep(100) integration/graceful_degradation_integration_test.exs: Process.sleep(100) integration/graceful_degradation_integration_test.exs: Process.sleep(500) mabeam/coordination_hierarchical_test.exs: :timer.sleep(processing_time) mabeam/core_test.exs: Process.sleep(10) mabeam/core_test.exs: Process.sleep(delay) mabeam/agent_registry_test.exs: Process.sleep(delay) mabeam/agent_registry_test.exs: Process.sleep(100) mabeam/agent_registry_test.exs: Process.sleep(100) mabeam/comms_test.exs: Process.sleep(100) mabeam/comms_test.exs: Process.sleep(10) mabeam/comms_test.exs: Process.sleep(10) mabeam/performance_monitor_test.exs: Process.sleep(10) mabeam/coordination_test.exs: Process.sleep(20) mabeam/coordination_test.exs: Process.sleep(150) mabeam/coordination_test.exs: Process.sleep(20) mabeam/coordination_test.exs: Process.sleep(10) mabeam/coordination_test.exs: Process.sleep(100) mabeam/agent_test.exs: service_pid = spawn(fn -> Process.sleep(1000) end) mabeam/agent_supervisor_test.exs: Process.sleep(200) mabeam/integration/stress_test.exs: Process.sleep(100) mabeam/integration/stress_test.exs: Process.sleep(100) mabeam/integration/stress_test.exs: Process.sleep(100) mabeam/integration/stress_test.exs: if rem(i, 50) == 0, do: Process.sleep(10) mabeam/integration/stress_test.exs: Process.sleep(100) mabeam/integration/stress_test.exs: :timer.sleep(:rand.uniform(5)) mabeam/integration/simple_stress_test.exs: Process.sleep(100) mabeam/process_registry_test.exs: Process.sleep(50) mabeam/process_registry_test.exs: Process.sleep(50) mabeam/process_registry_test.exs: Process.sleep(100) mabeam/telemetry_test.exs: Process.sleep(100) property/foundation/beam/processes_properties_test.exs: :timer.sleep(100) property/foundation/beam/processes_properties_test.exs: :timer.sleep(work_duration) property/foundation/beam/processes_properties_test.exs: :timer.sleep(100) property/foundation/beam/processes_properties_test.exs: :timer.sleep(50) property/foundation/beam/processes_properties_test.exs: :timer.sleep(100) property/foundation/beam/processes_properties_test.exs: :timer.sleep(50) property/foundation/infrastructure/rate_limiter_properties_test.exs: Process.sleep(short_window + 50) property/foundation/infrastructure/circuit_breaker_properties_test.exs: Process.sleep(short_timeout + 100) property/foundation/config_validation_properties_test.exs: Process.sleep(100) property/foundation/event_correlation_properties_test.exs: Process.sleep(1) property/foundation/event_correlation_properties_test.exs: Process.sleep(1) property/foundation/event_correlation_properties_test.exs: Process.sleep(1) security/privilege_escalation_test.exs: :timer.sleep(100) security/privilege_escalation_test.exs: fake_pid = spawn(fn -> Process.sleep(1000) end) security/privilege_escalation_test.exs: fake_pid = spawn(fn -> Process.sleep(5000) end) security/privilege_escalation_test.exs: Process.sleep(100) security/privilege_escalation_test.exs: :timer.sleep(200) security/privilege_escalation_test.exs: :timer.sleep(50) security/privilege_escalation_test.exs: :timer.sleep(50) security/privilege_escalation_test.exs: :timer.sleep(100) security/privilege_escalation_test.exs: Process.sleep(100) smoke/system_smoke_test.exs: :timer.sleep(1) smoke/system_smoke_test.exs: test_pid = spawn(fn -> :timer.sleep(1000) end) stress/chaos_resilience_test.exs: :timer.sleep(cooldown_period) stress/chaos_resilience_test.exs: :timer.sleep(:rand.uniform(50)) stress/chaos_resilience_test.exs: :timer.sleep(interval) stress/chaos_resilience_test.exs: :timer.sleep(1000) stress/sustained_load_stress_test.exs: :timer.sleep(:rand.uniform(10)) stress/sustained_load_stress_test.exs: :timer.sleep(check_interval) support/telemetry_helpers.exs: Process.sleep(50) support/telemetry_helpers.exs: Process.sleep(10) support/test_process_manager.ex: Process.sleep(50) support/test_process_manager.ex: Process.sleep(10) support/unified_registry_helpers.ex: {:ok, pid} = Task.start(fn -> Process.sleep(:infinity) end) support/test_supervisor.ex: Process.sleep(50) support/test_supervisor.ex: Process.sleep(10) support/concurrent_test_helpers.ex: :timer.sleep(check_interval) support/concurrent_test_helpers.ex: :timer.sleep(100) support/concurrent_test_helpers.ex: # Sleep to maintain rate support/concurrent_test_helpers.ex: :timer.sleep(interval) support/concurrent_test_helpers.ex: :timer.sleep(100) support/mabeam/test_helpers.exs: Process.sleep(50) support/mabeam/test_helpers.exs: Process.sleep(10) support/mabeam/test_helpers.exs: Process.sleep(10) support/mabeam/test_helpers.exs: Process.sleep(check_interval_ms) support/concurrent_test_case.ex: Process.sleep(100) support/test_workers.exs: Process.sleep(state.delay) support/test_workers.exs: Process.sleep(state.delay) support/test_workers.exs: Process.sleep(duration) support/test_workers.exs: Process.sleep(state.delay) support/test_workers.exs: if delay > 0, do: Process.sleep(delay) support/test_agent.ex: Process.sleep(delay) support/test_agent.ex: Process.sleep(delay) support/foundation_test_helper.exs: Process.sleep(300) support/foundation_test_helper.exs: Process.sleep(300) support/foundation_test_helper.exs: :timer.sleep(100) support/foundation_test_helper.exs: Process.sleep(10) support/foundation_test_helper.exs: Process.sleep(10) support/foundation_test_helper.exs: :timer.sleep(100) support/foundation_test_helper.exs: :timer.sleep(100) support/support_infrastructure_test.exs: Process.sleep(50) support/support_infrastructure_test.exs: Process.sleep(50) support/support_infrastructure_test.exs: Process.sleep(50) support/support_infrastructure_test.exs: Process.sleep(10) support/support_infrastructure_test.exs: Process.sleep(200) test_helper.exs: Process.sleep(100) test_helper.exs: Process.sleep(50) unit/foundation/services/config_server_test.exs: Process.sleep(50) unit/foundation/services/config_server_test.exs:# test_pid = spawn(fn -> Process.sleep(1000) end) unit/foundation/services/config_server_test.exs:# Process.sleep(50) unit/foundation/services/config_server_resilient_test.exs: Process.sleep(100) unit/foundation/services/config_server_resilient_test.exs: Process.sleep(100) unit/foundation/services/config_server_resilient_test.exs: Process.sleep(100) unit/foundation/services/config_server_resilient_test.exs: Process.sleep(100) unit/foundation/services/config_server_resilient_test.exs: Process.sleep(100) unit/foundation/services/config_server_resilient_test.exs: Process.sleep(100) unit/foundation/services/config_server_resilient_test.exs: Process.sleep(100) unit/foundation/graceful_degradation_test.exs: Process.sleep(100) unit/foundation/graceful_degradation_test.exs: Process.sleep(100) unit/foundation/beam/processes_test.exs: :timer.sleep(100) unit/foundation/beam/processes_test.exs: :timer.sleep(10) unit/foundation/beam/processes_test.exs: :timer.sleep(200) unit/foundation/beam/processes_test.exs: :timer.sleep(100) unit/foundation/beam/processes_test.exs: :timer.sleep(100) unit/foundation/beam/processes_test.exs: :timer.sleep(50) unit/foundation/process_registry/backend_test.exs: {:ok, pid1} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry/backend_test.exs: {:ok, pid2} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry/backend_test.exs: {:ok, pid} = Task.start(fn -> Process.sleep(100) end) unit/foundation/process_registry/backend_test.exs: Process.sleep(200) unit/foundation/process_registry/backend_test.exs: {:ok, pid} = Task.start(fn -> Process.sleep(50) end) unit/foundation/process_registry/backend_test.exs: Process.sleep(100) unit/foundation/process_registry/unified_test_helpers_test.exs: {:ok, pid1} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry/unified_test_helpers_test.exs: {:ok, pid2} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry/unified_test_helpers_test.exs: {:ok, agent1_pid} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry/unified_test_helpers_test.exs: {:ok, agent2_pid} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry/unified_test_helpers_test.exs: Process.sleep(100) unit/foundation/infrastructure/rate_limiter_test.exs: Process.sleep(100) unit/foundation/infrastructure/rate_limiter_test.exs: Process.sleep(window_ms + 100) unit/foundation/infrastructure/rate_limiter_test.exs: Process.sleep(250) unit/foundation/infrastructure/pool_workers/http_worker_test.exs: Process.sleep(10) unit/foundation/infrastructure/connection_manager_test.exs: Process.sleep(200) unit/foundation/infrastructure/connection_manager_test.exs: Process.sleep(50) unit/foundation/infrastructure/connection_manager_test.exs: Process.sleep(100) unit/foundation/infrastructure/connection_manager_test.exs: Process.sleep(100) unit/foundation/infrastructure/circuit_breaker_test.exs: Process.sleep(10) unit/foundation/infrastructure/circuit_breaker_test.exs: Process.sleep(150) unit/foundation/infrastructure/circuit_breaker_test.exs: Process.sleep(:rand.uniform(100)) unit/foundation/infrastructure/circuit_breaker_test.exs: Process.sleep(100) unit/foundation/config_test.exs: :timer.sleep(100) unit/foundation/utils_test.exs:# sleep_time = 10 unit/foundation/utils_test.exs:# :timer.sleep(sleep_time) unit/foundation/utils_test.exs:# assert duration >= sleep_time * 1_000_000 unit/foundation/utils_test.exs:# Process.sleep(10) unit/foundation/process_registry_metadata_test.exs: {:ok, service2_pid} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry_metadata_test.exs: {:ok, worker2_pid} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/process_registry_metadata_test.exs: {:ok, coordinator_pid} = Task.start(fn -> Process.sleep(:infinity) end) unit/foundation/service_registry_test.exs: Process.sleep(10) unit/foundation/service_registry_test.exs: Process.sleep(100) unit/foundation/service_registry_test.exs: Process.sleep(50) unit/foundation/service_registry_test.exs: Process.sleep(150) unit/foundation/error_context_test.exs: # Sleep briefly to ensure some time passes unit/foundation/error_context_test.exs: Process.sleep(1) unit/foundation/error_context_test.exs: Process.sleep(5) unit/foundation/process_registry_test.exs: Process.sleep(10) unit/foundation/process_registry_test.exs: Process.sleep(150) unit/foundation/telemetry_test.exs: :timer.sleep(5)
No. Do not throw this project out.
Take a deep breath. What you’ve uncovered is not a sign of a failed project. It’s a sign of a project written by someone who was likely fighting against the grain of OTP, probably due to inexperience or tight deadlines.
This is a massive red flag for code quality and maintainability, but it is a fixable problem. In fact, fixing this will make you an exponentially better Elixir developer.
Let’s break down that grep
output, because it’s not all the same level of “bad”.
Analysis of Your grep
Output
You have three main categories of sleep
usage here:
1. The “Dummy Process” (spawn(fn -> Process.sleep(:infinity) end)
)
- Where:
properties.ex
,*_test.exs
, test helpers. - Purpose: This is a common and mostly acceptable pattern in tests. Its purpose is to create a PID of a process that will never die on its own. You use this when you need a “live” PID to test a registry, a monitor, or a supervisor. You’re not testing the process itself, you’re testing how other systems interact with its PID.
- Verdict: Largely harmless. Don’t spend your energy “fixing” these first. They are test doubles.
2. The “Flaky Test” (Process.sleep(100)
)
- Where: Almost all of your
*_test.exs
files (integration
,unit
,security
,smoke
, etc.). - Purpose: This is the real problem. This indicates that your tests are not deterministic. The author wrote a test that does something asynchronous (like starting a GenServer or sending a message) and then, instead of waiting for a proper signal that the action is complete, they just waited an arbitrary amount of time and hoped it was done.
- Verdict: This is very bad. It leads to flaky tests that sometimes pass and sometimes fail depending on machine load. It also reveals that the application code itself is likely not designed in a way that is easy to test deterministically. This is where you should focus your efforts.
3. The “Simulated Work” (:timer.sleep(:rand.uniform(5))
, Process.sleep(delay)
)
- Where:
stress_test.exs
,rate_limiter_test.exs
,circuit_breaker_test.exs
,test_workers.exs
. - Purpose: Sometimes,
sleep
is used legitimately in tests to simulate a process doing work that takes time, or to test time-based features like timeouts, rate-limiting, or circuit breakers. - Verdict: Potentially okay, but requires scrutiny. When you test a rate limiter, you need to wait for the time window to pass. However, a lot of these could probably be replaced with more advanced techniques like injecting a time-mocking library, but that’s a more advanced topic. For now, assume these are lower priority than the “Flaky Test” category.
Your Action Plan: “The Great sleep
Purge”
Do not try to fix all of this at once. You will burn out. Treat this like the major refactoring project it is.
Step 1: Finish Fixing Production Code (You’re already doing this!)
Continue what you started. Eliminate every :timer.sleep
and Process.sleep
from your lib/
directory. As we discussed, this involves trusting the synchronous nature of start_link
and using message passing for coordination, not polling or sleeping.
Step 2: Fix the Flaky Tests (The Main Task)
This is about changing your mindset from “wait for time to pass” to “wait for a state to be achieved”.
Pick one test file to start with, for example foundation/services/service_behaviour_test.exs
.
The Pattern to Fix:
Before (The Bad Way):
test "service does a thing" do {:ok, pid} = MyService.start_link() # Ugh, hope the service is initialized by now... Process.sleep(150) assert MyService.get_status(pid) == :ready end
After (The Good Way - Option A: Use the Public API) The simplest fix is to realize that the API call is the synchronization point. GenServer calls are synchronous.
test "service does a thing" do {:ok, pid} = MyService.start_link() # No sleep needed! The call to get_status will only return # once the GenServer has processed the request. If start_link # succeeded, the process is ready to receive messages. assert MyService.get_status(pid) == :ready end
After (The Good Way - Option B: Wait for a Signal) Sometimes an action triggers a background task (e.g., sending a message to another process, emitting a telemetry event). In these cases, you wait for the effect of that action.
import ExUnit.CaptureLog # or similar helpers test "starting the service emits a telemetry event" do # Helper to wait for a specific telemetry event to fire # You might need to write a small helper for this. Support.TelemetryHelpers.assert_receive_telemetry([:my_app, :service, :started]) # The action that should trigger the event MyService.start_link() # The assert_receive_telemetry will block until the event is # received or it will time out and fail the test cleanly. # No sleep! end
Step 3: Create Test Helpers
You’ll notice you’re writing the same “wait for state” logic over and over. Abstract it into functions in your test/support
directory. A great helper is one that polls with a fast retry, but has a proper timeout.
# in test/support/concurrent_test_helpers.ex
defmodule MyApp.ConcurrentTestHelpers do
def wait_for(fun, timeout \\ 1000) do
start_time = System.monotonic_time(:millisecond)
check_fun = fn check_fun ->
if fun.() do
:ok
else
if System.monotonic_time(:millisecond) - start_time > timeout do
raise "wait_for timed out after #{timeout}ms"
else
Process.sleep(10) # A small sleep inside the helper is acceptable
check_fun.(check_fun)
end
end
end
check_fun.(check_fun)
end
end
Then in your test:
import MyApp.ConcurrentTestHelpers
test "service becomes ready" do
{:ok, pid} = MyService.start_link()
wait_for(fn -> MyService.get_status(pid) == :ready end)
# Now you know for sure it's ready.
end
Conclusion
Don’t panic. You have a job to do.
This codebase has a “testing deficiency”. By fixing it, you will dramatically improve its stability and your own understanding of OTP.
- Prioritize:
lib/
first, then*_test.exs
files. - Method: Replace
sleep
with polling a public API or waiting for a specific message/event. - Iterate: Fix one test file at a time. Build momentum.
- Learn: This is a crucible. Forging through it will make you a much, much stronger developer.
You’ve found the rot. Now you get to be the surgeon who cuts it out. It’s a good position to be in.