Skip to content
Permalink
Browse files

Revert "FIX: remove deperecated Minitest global assertions"

This reverts commit fdb8425.
  • Loading branch information
lis2 authored and SamSaffron committed Oct 20, 2019
1 parent c64e3d3 commit ae0bf0f0da6b827707df2f37af1b7c4b547e0f82
@@ -6,7 +6,7 @@

describe asset_file_names do
it 'should contain .js files' do
_(asset_file_names).must_include('message-bus.js')
asset_file_names.must_include('message-bus.js')
end
end

@@ -15,22 +15,22 @@ def new_test_bus

describe "API parity" do
it "has the same public methods as the base class" do
_(@bus.public_methods.sort).must_equal MessageBus::Backends::Base.new(MESSAGE_BUS_CONFIG).public_methods.sort
@bus.public_methods.sort.must_equal MessageBus::Backends::Base.new(MESSAGE_BUS_CONFIG).public_methods.sort
end
end

it "should be able to access the backlog" do
@bus.publish "/foo", "bar"
@bus.publish "/foo", "baz"

_(@bus.backlog("/foo", 0).to_a).must_equal [
@bus.backlog("/foo", 0).to_a.must_equal [
MessageBus::Message.new(1, 1, '/foo', 'bar'),
MessageBus::Message.new(2, 2, '/foo', 'baz')
]
end

it "should initialize with max_backlog_size" do
_(PUB_SUB_CLASS.new({}, 2000).max_backlog_size).must_equal 2000
PUB_SUB_CLASS.new({}, 2000).max_backlog_size.must_equal 2000
end

it "should truncate channels correctly" do
@@ -44,7 +44,7 @@ def new_test_bus
@bus.publish "/foo", t
end

_(@bus.backlog("/foo").to_a).must_equal [
@bus.backlog("/foo").to_a.must_equal [
MessageBus::Message.new(3, 3, '/foo', 'three'),
MessageBus::Message.new(4, 4, '/foo', 'four'),
]
@@ -56,14 +56,14 @@ def new_test_bus
@bus.publish "/bar", "two"
@bus.publish "/baz", "three"

_(@bus.global_backlog.length).must_equal 2
@bus.global_backlog.length.must_equal 2
end

it "should be able to grab a message by id" do
id1 = @bus.publish "/foo", "bar"
id2 = @bus.publish "/foo", "baz"
_(@bus.get_message("/foo", id2)).must_equal MessageBus::Message.new(2, 2, "/foo", "baz")
_(@bus.get_message("/foo", id1)).must_equal MessageBus::Message.new(1, 1, "/foo", "bar")
@bus.get_message("/foo", id2).must_equal MessageBus::Message.new(2, 2, "/foo", "baz")
@bus.get_message("/foo", id1).must_equal MessageBus::Message.new(1, 1, "/foo", "bar")
end

it "should have the correct number of messages for multi threaded access" do
@@ -82,13 +82,13 @@ def new_test_bus

it "should be able to encode and decode messages properly" do
m = MessageBus::Message.new 1, 2, '||', '||'
_(MessageBus::Message.decode(m.encode)).must_equal m
MessageBus::Message.decode(m.encode).must_equal m
end

it "should allow us to get last id on a channel" do
_(@bus.last_id("/foo")).must_equal 0
@bus.last_id("/foo").must_equal 0
@bus.publish("/foo", "one")
_(@bus.last_id("/foo")).must_equal 1
@bus.last_id("/foo").must_equal 1
end

describe "readonly" do
@@ -109,16 +109,16 @@ def new_test_bus
3.times do
result = @bus.publish "/foo", "bar"
assert_nil result
_(Thread.list.length).must_equal(current_threads_length + 1)
Thread.list.length.must_equal(current_threads_length + 1)
end

@bus.pub_redis.slaveof "no", "one"
sleep 0.01

(Thread.list - current_threads).each(&:join)
_(Thread.list.length).must_equal current_threads_length
Thread.list.length.must_equal current_threads_length

_(@bus.backlog("/foo", 0).map(&:data)).must_equal ["bar", "bar"]
@bus.backlog("/foo", 0).map(&:data).must_equal ["bar", "bar"]
end
end

@@ -131,24 +131,24 @@ def new_test_bus
@bus.publish "/foo", "bar"
expected_backlog_size += 1

_(@bus.global_backlog.length).must_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).must_equal expected_backlog_size
@bus.global_backlog.length.must_equal expected_backlog_size
@bus.backlog("/foo", 0).length.must_equal expected_backlog_size

sleep 1.25 # Should now be at time =~ 1.25s. Our backlog should have expired by now.
expected_backlog_size = 0

case MESSAGE_BUS_CONFIG[:backend]
when :postgres
# Force triggering backlog expiry: postgres backend doesn't expire backlogs on a timer, but at publication time.
_(@bus.global_backlog.length).wont_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).wont_equal expected_backlog_size
@bus.global_backlog.length.wont_equal expected_backlog_size
@bus.backlog("/foo", 0).length.wont_equal expected_backlog_size
@bus.publish "/foo", "baz"
expected_backlog_size += 1
end

# Assert that the backlog did expire, and now has only the new publication in it.
_(@bus.global_backlog.length).must_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).must_equal expected_backlog_size
@bus.global_backlog.length.must_equal expected_backlog_size
@bus.backlog("/foo", 0).length.must_equal expected_backlog_size

sleep 0.75 # Should now be at time =~ 2s

@@ -168,8 +168,8 @@ def new_test_bus
else
# Assert that the backlog did not expire, and has all of our publications since the last expiry.
end
_(@bus.global_backlog.length).must_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).must_equal expected_backlog_size
@bus.global_backlog.length.must_equal expected_backlog_size
@bus.backlog("/foo", 0).length.must_equal expected_backlog_size
end

it "can set backlog age on publish" do
@@ -183,32 +183,32 @@ def new_test_bus
@bus.publish "/foo", "bar", max_backlog_age: 1
expected_backlog_size += 1

_(@bus.global_backlog.length).must_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).must_equal expected_backlog_size
@bus.global_backlog.length.must_equal expected_backlog_size
@bus.backlog("/foo", 0).length.must_equal expected_backlog_size

sleep 1.25 # Should now be at time =~ 1.25s. Our backlog should have expired by now.
expected_backlog_size = 0

case MESSAGE_BUS_CONFIG[:backend]
when :postgres
# Force triggering backlog expiry: postgres backend doesn't expire backlogs on a timer, but at publication time.
_(@bus.global_backlog.length).wont_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).wont_equal expected_backlog_size
@bus.global_backlog.length.wont_equal expected_backlog_size
@bus.backlog("/foo", 0).length.wont_equal expected_backlog_size
@bus.publish "/foo", "baz", max_backlog_age: 1
expected_backlog_size += 1
end

# Assert that the backlog did expire, and now has only the new publication in it.
_(@bus.global_backlog.length).must_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).must_equal expected_backlog_size
@bus.global_backlog.length.must_equal expected_backlog_size
@bus.backlog("/foo", 0).length.must_equal expected_backlog_size

# for the time being we can give pg a pass here
# TODO: make the implementation here consistent
if MESSAGE_BUS_CONFIG[:backend] != :postgres
# ids are not opaque we expect them to be reset on our channel if it
# got cleared due to an expire, the reason for this is cause we will leak entries due to tracking
# this in turn can bloat storage for the backend
_(@bus.last_id("/foo")).must_equal initial_id
@bus.last_id("/foo").must_equal initial_id
end

sleep 0.75 # Should now be at time =~ 2s
@@ -229,8 +229,8 @@ def new_test_bus
else
# Assert that the backlog did not expire, and has all of our publications since the last expiry.
end
_(@bus.global_backlog.length).must_equal expected_backlog_size
_(@bus.backlog("/foo", 0).length).must_equal expected_backlog_size
@bus.global_backlog.length.must_equal expected_backlog_size
@bus.backlog("/foo", 0).length.must_equal expected_backlog_size
end

it "can set backlog size on publish" do
@@ -240,7 +240,7 @@ def new_test_bus
@bus.publish "/foo", "bar", max_backlog_size: 2
@bus.publish "/foo", "bar", max_backlog_size: 2

_(@bus.backlog("/foo").length).must_equal 2
@bus.backlog("/foo").length.must_equal 2
end

it "should be able to access the global backlog" do
@@ -267,7 +267,7 @@ def new_test_bus
]
end

_(@bus.global_backlog.to_a).must_equal expected_messages
@bus.global_backlog.to_a.must_equal expected_messages
end

it "should correctly omit dropped messages from the global backlog" do
@@ -291,7 +291,7 @@ def new_test_bus
]
end

_(@bus.global_backlog.to_a).must_equal expected_messages
@bus.global_backlog.to_a.must_equal expected_messages
end

it "should cope with a storage reset cleanly" do
@@ -320,8 +320,8 @@ def new_test_bus

t.kill

_(got.map { |m| m.data }).must_equal ["two", "three"]
_(got[1].global_id).must_equal 1
got.map { |m| m.data }.must_equal ["two", "three"]
got[1].global_id.must_equal 1
end

it "should support clear_every setting" do
@@ -333,10 +333,10 @@ def new_test_bus
@bus.publish "/bar", "21"
@bus.publish "/baz", "31"
@bus.publish "/bar", "41"
_(@bus.global_backlog.length).must_equal 4
@bus.global_backlog.length.must_equal 4

@bus.publish "/baz", "51"
_(@bus.global_backlog.length).must_equal 2
@bus.global_backlog.length.must_equal 2
end

it "should be able to subscribe globally with recovery" do
@@ -358,8 +358,8 @@ def new_test_bus

t.kill

_(got.length).must_equal 3
_(got.map { |m| m.data }).must_equal ["11", "12", "13"]
got.length.must_equal 3
got.map { |m| m.data }.must_equal ["11", "12", "13"]
end

it "should handle subscribe on single channel, with recovery" do
@@ -381,7 +381,7 @@ def new_test_bus

t.kill

_(got.map { |m| m.data }).must_equal ["11", "13"]
got.map { |m| m.data }.must_equal ["11", "13"]
end

it "should not get backlog if subscribe is called without params" do
@@ -406,14 +406,14 @@ def new_test_bus

t.kill

_(got.map { |m| m.data }).must_equal ["12"]
got.map { |m| m.data }.must_equal ["12"]
end

it 'should not lose redis config' do
test_only :redis
redis_config = { connector: Redis::Client::Connector }
@bus.instance_variable_set(:@redis_config, redis_config)
@bus.send(:new_redis_connection)
_(@bus.instance_variable_get(:@redis_config)[:connector]).must_equal Redis::Client::Connector
expect(@bus.instance_variable_get(:@redis_config)[:connector]).must_equal Redis::Client::Connector
end
end

1 comment on commit ae0bf0f

@discoursereviewbot

This comment has been minimized.

Copy link

discoursereviewbot commented on ae0bf0f Feb 14, 2020

system posted:

This commit appears in #215 which was merged by @SamSaffron.

Please sign in to comment.
You can’t perform that action at this time.