Skip to content

Commit

Permalink
add tests for extended tag feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ithanil committed Dec 4, 2024
1 parent 1ca8dcd commit 20b8f3c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
44 changes: 44 additions & 0 deletions spec/models/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@
expect(server.id).to eq 'test-3'
end
end

context 'and with none tag argument' do
let(:server) { described_class.find_available('none') }

it 'returns untagged server with lowest load' do
expect(server.id).to eq 'test-3'
end
end

context 'and with none! tag argument' do
let(:server) { described_class.find_available('none!') }

it 'returns untagged server with lowest load' do
expect(server.id).to eq 'test-3'
end
end
end

context 'with differently tagged servers' do
Expand Down Expand Up @@ -366,6 +382,11 @@
redis.sadd?('servers', 'test-4')
redis.sadd?('server_enabled', 'test-4')
redis.zadd('server_load', 1, 'test-4')
redis.mapped_hmset('server:test-5', url: 'https://test-5.example.com/bigbluebutton/api', secret: 'test-5-secret',
tag: 'test-tag2', enabled: 'true')
redis.sadd?('servers', 'test-5')
redis.sadd?('server_enabled', 'test-5')
redis.zadd('server_load', 1, 'test-5')
end
end

Expand All @@ -391,6 +412,29 @@
expect(server.tag).to eq 'test-tag'
end
end

context 'and optional tag list argument' do
let(:server) { described_class.find_available('test-tag,test-tag2') }

it 'returns matching tagged server with lowest load' do
expect(server.id).to eq 'test-5'
expect(server.url).to eq 'https://test-5.example.com/bigbluebutton/api'
expect(server.secret).to eq 'test-5-secret'
expect(server.tag).to eq 'test-tag2'
expect(server.enabled).to be true
expect(server.state).to be_nil
expect(server.load).to eq 1
end
end

context 'and required tag list argument' do
let(:server) { described_class.find_available('test-tag,test-tag2!') }

it 'returns matching tagged server with lowest load' do
expect(server.id).to eq 'test-5'
expect(server.tag).to eq 'test-tag2'
end
end
end

context 'with no matching tagged servers' do
Expand Down
46 changes: 45 additions & 1 deletion test/models/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class ServerTest < ActiveSupport::TestCase
end
end

test 'Server find_available without or with empty tag returns untagged server with lowest load' do
test 'Server find_available without or with empty tag or with none tag returns untagged server with lowest load' do
RedisStore.with_connection do |redis|
redis.mapped_hmset('server:test-1', url: 'https://test-1.example.com/bigbluebutton/api', secret: 'test-1-secret',
tag: 'test-tag', enabled: 'true')
Expand Down Expand Up @@ -276,6 +276,12 @@ class ServerTest < ActiveSupport::TestCase

server = Server.find_available('!')
assert_equal('test-3', server.id)

server = Server.find_available('none')
assert_equal('test-3', server.id)

server = Server.find_available('none!')
assert_equal('test-3', server.id)
end

test 'Server find_available with tag argument returns matching tagged server with lowest load' do
Expand Down Expand Up @@ -316,6 +322,44 @@ class ServerTest < ActiveSupport::TestCase
assert_equal('test-tag', server.tag)
end

test 'Server find_available with multiple tag arguments returns matching tagged server with lowest load' do
RedisStore.with_connection do |redis|
redis.mapped_hmset('server:test-1', url: 'https://test-1.example.com/bigbluebutton/api', secret: 'test-1-secret',
enabled: 'true')
redis.sadd?('servers', 'test-1')
redis.sadd?('server_enabled', 'test-1')
redis.zadd('server_load', 1, 'test-1')
redis.mapped_hmset('server:test-2', url: 'https://test-2.example.com/bigbluebutton/api', secret: 'test-2-secret',
tag: 'test-tag', enabled: 'true')
redis.sadd?('servers', 'test-2')
redis.sadd?('server_enabled', 'test-2')
redis.zadd('server_load', 3, 'test-2')
redis.mapped_hmset('server:test-3', url: 'https://test-3.example.com/bigbluebutton/api', secret: 'test-3-secret',
tag: 'test-tag2', enabled: 'true')
redis.sadd?('servers', 'test-3')
redis.sadd?('server_enabled', 'test-3')
redis.zadd('server_load', 2, 'test-3')
redis.mapped_hmset('server:test-4', url: 'https://test-4.example.com/bigbluebutton/api', secret: 'test-4-secret',
tag: 'wrong-tag', enabled: 'true')
redis.sadd?('servers', 'test-4')
redis.sadd?('server_enabled', 'test-4')
redis.zadd('server_load', 1, 'test-4')
end

server = Server.find_available('test-tag,test-tag2')
assert_equal('test-3', server.id)
assert_equal('https://test-3.example.com/bigbluebutton/api', server.url)
assert_equal('test-3-secret', server.secret)
assert_equal('test-tag2', server.tag)
assert(server.enabled)
assert_nil(server.state)
assert_equal(2, server.load)

server = Server.find_available('test-tag,test-tag2!')
assert_equal('test-3', server.id)
assert_equal('test-tag2', server.tag)
end

test 'Server find_available with optional tag returns untagged server with lowest load if no matching tagged server available' do
RedisStore.with_connection do |redis|
redis.mapped_hmset('server:test-1', url: 'https://test-1.example.com/bigbluebutton/api', secret: 'test-1-secret',
Expand Down

0 comments on commit 20b8f3c

Please sign in to comment.