4295: Add test that large numbers of events are handled efficiently and correctly.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Thu, 23 Oct 2014 19:52:04 +0000 (15:52 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Thu, 23 Oct 2014 19:52:04 +0000 (15:52 -0400)
services/api/test/integration/websocket_test.rb

index fbc18c50c77171c64fae4c647517d3eba56f699e..4864c53745a929673eca6f647791731ba58e561d 100644 (file)
@@ -603,4 +603,47 @@ class WebsocketTest < ActionDispatch::IntegrationTest
 
   end
 
+  test "connect, subscribe, lots of events" do
+    state = 1
+    event_count = 0
+    log_start = Log.order(:id).last.id
+
+    authorize_with :admin
+
+    ws_helper :admin, false do |ws|
+      EM::Timer.new 8 do
+        # Needs a longer timeout than the default
+        ws.close
+      end
+
+      ws.on :open do |event|
+        ws.send ({method: 'subscribe'}.to_json)
+      end
+
+      ws.on :message do |event|
+        d = Oj.load event.data
+        case state
+        when 1
+          assert_equal 200, d["status"]
+          ActiveRecord::Base.transaction do
+            (1..202).each do
+              spec = Specimen.create
+            end
+          end
+          state = 2
+        when 2
+          event_count += 1
+          assert_equal d['id'], event_count+log_start
+          if event_count == 202
+            ws.close
+          end
+        end
+      end
+
+    end
+
+    assert_equal 202, event_count
+  end
+
+
 end