Skip to content

Commit

Permalink
added test case to check against race conditions of write with the ga…
Browse files Browse the repository at this point in the history
…rbage collection
  • Loading branch information
planthaber committed Aug 28, 2014
1 parent 401b17e commit d660b0f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/test_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,38 @@ def with_stub_task_context(task_name)
end

it "returns a code 201 'Created' when the port was written correctly" do
(0..20000).each do
with_stub_task_context "task" do |task|
port = task.create_input_port 'port', '/double'
post "/tasks/localhost/task/ports/port/write", value: "10.0"
assert_equal 201, last_response.status
assert_equal 10.0, port.read
end
end
end

describe "/GCwrite" do
it "does also work if the GC runs" do
gcruns = 0
Thread.new do
loop do
#sleep 0.01
GC.start
gcruns += 1
end
end
(0..1000).each do |run|
with_stub_task_context "task" do |task|
port = task.create_input_port 'port', '/double'
post "/tasks/localhost/task/ports/port/write", value: "10.0"
assert_equal 201, last_response.status
assert_equal 10.0, port.read
end
p "run #{run} with #{gcruns} GC runs"
gcruns = 0
end
end
end

end
end

5 comments on commit d660b0f

@doudou
Copy link
Collaborator

@doudou doudou commented on d660b0f Aug 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ... not the best way to do it. Can we go back to using pull requests ?

@doudou
Copy link
Collaborator

@doudou doudou commented on d660b0f Aug 28, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even more because what you basically claim here is that POST works because ... you can exploit a memory leak that exist in async. Assuming that some of these rock-webapp could actually run for hours, what will happen in the end is that some ports will end up with as many connections as there has been writes done to them. Not exactly the best strategy ...

@planthaber
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, when the ruby port element gets GCed, the connection is not closed?

You should start an issue on this on https://github.com/rock-core/tools-orocosrb, this whould be a serious bug.

@doudou
Copy link
Collaborator

@doudou doudou commented on d660b0f Sep 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, basically, and it is both a serious bug and a not-so-serious one.

It is a bug in async writer and reader code. These are usually created in the one-object-per-port category, not repeatedly like in the webapp. So, it is a bad bug with low impact.

@doudou
Copy link
Collaborator

@doudou doudou commented on d660b0f Sep 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.