Skip to content

Commit 78d46f2

Browse files
committed
✅ Make FakeServer more robust against disconnect
When the client disconnects without a `LOGOUT`, that shouldn't cause a secondary error in the test output. Most of the time, it's just a distraction. In some cases, the test is intentionally triggering a bad disconnect, and the server's failure could break the test.
1 parent d10881e commit 78d46f2

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

test/net/imap/fake_server/command_reader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def get_command
2121
$2 or socket.print "+ Continue\r\n"
2222
buf << socket.read(Integer($1))
2323
end
24+
throw :eof if buf.empty?
2425
@last_command = parse(buf)
2526
end
2627

test/net/imap/fake_server/connection.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def unsolicited(...) writer.untagged(...) end
2323

2424
def run
2525
writer.greeting
26-
router << reader.get_command until state.logout?
26+
catch(:eof) do
27+
router << reader.get_command until state.logout?
28+
end
2729
ensure
2830
close
2931
end

test/net/imap/fake_server/test_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ def run_fake_server_in_thread(ignore_io_error: false, timeout: 10, **opts)
1414
end
1515
yield server
1616
ensure
17-
server&.shutdown
17+
begin
18+
server&.shutdown
19+
rescue IOError
20+
raise unless ignore_io_error
21+
end
1822
end
1923
end
2024

0 commit comments

Comments
 (0)