Skip to content
Permalink
Browse files

FIX: remove deperecated Minitest global assertions

  • Loading branch information
lis2 authored and SamSaffron committed Oct 18, 2019
1 parent 55a8d42 commit 79c3f08daf0173c5faa7d99b1106999cdca8d85d
@@ -5,7 +5,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

@@ -13,22 +13,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
@@ -42,7 +42,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'),
]
@@ -54,14 +54,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
@@ -80,13 +80,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
@@ -107,16 +107,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

@@ -129,24 +129,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

@@ -166,8 +166,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
@@ -181,32 +181,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
@@ -227,8 +227,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
@@ -238,7 +238,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
@@ -265,7 +265,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
@@ -289,7 +289,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
@@ -318,8 +318,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
@@ -331,10 +331,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
@@ -356,8 +356,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
@@ -379,7 +379,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
@@ -404,14 +404,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)
expect(@bus.instance_variable_get(:@redis_config)[:connector]).must_equal Redis::Client::Connector
_(@bus.instance_variable_get(:@redis_config)[:connector]).must_equal Redis::Client::Connector
end
end

1 comment on commit 79c3f08

@discoursereviewbot

This comment has been minimized.

Copy link

discoursereviewbot commented on 79c3f08 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.