2014-05-16 19:39:37 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe LatencyTester do
|
|
|
|
|
|
2014-09-24 19:27:56 +00:00
|
|
|
let(:params) {{client_id: 'abc', ip_address: '10.1.1.1', connection_stale_time:40, connection_expire_time:60, channel_id: '1', gateway: 'gateway1'} }
|
2014-05-16 19:39:37 +00:00
|
|
|
|
2021-02-01 17:58:25 +00:00
|
|
|
before {
|
|
|
|
|
pending "Latency Tester removed from production"
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-16 19:39:37 +00:00
|
|
|
it "success" do
|
|
|
|
|
latency_tester = FactoryGirl.create(:latency_tester)
|
|
|
|
|
latency_tester.connection.should_not be_nil
|
|
|
|
|
latency_tester.connection.latency_tester.should_not be_nil
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "connect" do
|
|
|
|
|
it "no existing latency tester" do
|
|
|
|
|
latency_tester = LatencyTester.connect(params)
|
|
|
|
|
latency_tester.errors.any?.should be_false
|
|
|
|
|
latency_tester.connection.ip_address.should == params[:ip_address]
|
|
|
|
|
latency_tester.connection.stale_time.should == params[:connection_stale_time]
|
|
|
|
|
latency_tester.connection.expire_time.should == params[:connection_expire_time]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "existing latency tester, no connection" do
|
2014-05-19 13:46:03 +00:00
|
|
|
latency_tester = FactoryGirl.create(:latency_tester, client_id: params[:client_id], make_connection: false)
|
2014-05-16 19:39:37 +00:00
|
|
|
latency_tester.connection.should be_nil
|
|
|
|
|
|
2014-05-19 13:46:03 +00:00
|
|
|
latency_tester.client_id = params[:client_id]
|
2014-05-16 19:39:37 +00:00
|
|
|
latency_tester.save!
|
|
|
|
|
|
|
|
|
|
found = LatencyTester.connect(params)
|
|
|
|
|
found.should == latency_tester
|
|
|
|
|
found.connection.should_not be_nil
|
|
|
|
|
found.connection.aasm_state.should == Connection::CONNECT_STATE.to_s
|
|
|
|
|
found.connection.client_id.should == latency_tester.client_id
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "existing latency tester, existing connection" do
|
|
|
|
|
latency_tester = FactoryGirl.create(:latency_tester)
|
|
|
|
|
|
|
|
|
|
latency_tester.connection.aasm_state = Connection::STALE_STATE.to_s
|
|
|
|
|
latency_tester.save!
|
2015-03-09 14:44:12 +00:00
|
|
|
set_updated_at(latency_tester.connection, 6.hours.ago)
|
2014-05-16 19:39:37 +00:00
|
|
|
|
|
|
|
|
params[:client_id] = latency_tester.connection.client_id
|
|
|
|
|
|
|
|
|
|
found = LatencyTester.connect(params)
|
|
|
|
|
found.should == latency_tester
|
|
|
|
|
found.connection.should == latency_tester.connection
|
|
|
|
|
# state should have refreshed from stale to connected
|
|
|
|
|
found.connection.aasm_state.should == Connection::CONNECT_STATE.to_s
|
|
|
|
|
# updated_at needs to be poked on connection to keep stale non-stale
|
2015-03-09 14:44:12 +00:00
|
|
|
(found.connection.updated_at - latency_tester.connection.updated_at).to_i.should == 60 * 60 * 6 # 6hours
|
2014-05-16 19:39:37 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|