-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup partial message on reconnect
If a connection error occurs when part after a partial message is received, the partial message needs to be cleaned up to prevent a 'protocol error' from occuring. Signed-off-by: Michael Fraenkel <fraenkel@us.ibm.com>
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
.bundle | ||
*.gem | ||
.DS_Store | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'spec_helper' | ||
|
||
describe 'partial message behavior' do | ||
before do | ||
@s = NatsServerControl.new | ||
@s.start_server | ||
end | ||
|
||
after do | ||
@s.kill_server | ||
end | ||
|
||
it 'should not hold stale message data across a reconnect' do | ||
got_message = false | ||
expect do | ||
EM.run do | ||
timeout_em_on_failure(2) | ||
timeout_nats_on_failure(2) | ||
|
||
c1 = NATS.connect(:uri => @s.uri, :reconnect_time_wait => 0.25) | ||
wait_on_connections([c1]) do | ||
c1.subscribe('subject') do |msg| | ||
got_message = true | ||
msg.should eq('complete message') | ||
EM.stop | ||
NATS.stop | ||
end | ||
|
||
# Client receives partial message before server terminates | ||
c1.receive_data("MSG subject 2 32\r\nincomplete") | ||
|
||
@s.kill_server | ||
@s.start_server | ||
|
||
NATS.connect(:uri => @s.uri) do |c2| | ||
EM.add_timer(0.25) do | ||
c1.connected_server.should == @s.uri | ||
c1.flush { c2.publish('subject', 'complete message') } | ||
end | ||
end | ||
end | ||
end | ||
end.to_not raise_exception | ||
|
||
got_message.should be_true | ||
end | ||
end |