Skip to content

✅ Add a Mutex to FakeServer (for tests only) [backport: #317] #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions test/net/imap/fake_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def initialize(...)
@config = Configuration.new(...)
@tcp_server = TCPServer.new(config.hostname, config.port)
@connection = nil
@mutex = Thread::Mutex.new
end

def host; tcp_server.addr[2] end
Expand All @@ -84,9 +85,11 @@ def run
# accepted and closed. This may change in the future. Call #shutdown
# explicitly to ensure the server socket is unbound.
def shutdown
connection&.close
commands&.close if connection&.commands&.closed?&.!
tcp_server.close
@mutex.synchronize do
connection&.close
commands&.close if connection&.commands&.closed?&.!
tcp_server.close
end
end

# A Queue that contains every command the server has received.
Expand Down