-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from swaps19/improved_performance
Added 'id' param to all Ariadne 'get' methods
- Loading branch information
Showing
6 changed files
with
91 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require_relative 'data_util' | ||
require 'fakeredis' | ||
|
||
DataUtil.init_redis_cli(Redis.new) | ||
DataUtil.init_redis_cli(redis_obj: Redis.new) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,90 @@ | ||
require_relative 'test_helper' | ||
|
||
class AriadneTest < MiniTest::Test | ||
def test_insert_data | ||
app_name = 'test' | ||
data = { | ||
id: 123, | ||
state: 'active', | ||
app_name: app_name | ||
'id' => 123, | ||
'state' => 'active' | ||
} | ||
|
||
out = Ariadne.insert_data(data) | ||
out = Ariadne.insert_data(options: data, app_name: app_name) | ||
assert_equal Redis::Future, out.class | ||
end | ||
|
||
def test_get_data | ||
app_name = 'test' | ||
data = { | ||
id: 123, | ||
state: 'active', | ||
app_name: app_name | ||
'id' => 123, | ||
'state' => 'active' | ||
} | ||
|
||
Ariadne.insert_data(data) | ||
out = Ariadne.get_data(data[:app_name]) | ||
assert_equal JSON.parse(out[0])['id'], data[:id] | ||
Ariadne.insert_data(options: data, app_name: app_name) | ||
out = Ariadne.get_data(app_name: app_name) | ||
assert_equal JSON.parse(out[0])['id'], data['id'] | ||
end | ||
|
||
def test_get_data_with_time_diff_without_delay_should_be_empty | ||
app_name = 'test' | ||
data = { | ||
id: 123, | ||
state: 'active', | ||
app_name: app_name | ||
'id' => 123, | ||
'state' => 'active' | ||
} | ||
|
||
Ariadne.insert_data(data) | ||
out = Ariadne.get_data_with_time_difference(app_name) | ||
Ariadne.insert_data(options: data, app_name: app_name) | ||
out = Ariadne.get_data_with_time_difference(app_name: app_name) | ||
assert_empty JSON.parse(out) | ||
end | ||
|
||
def test_get_data_with_time_diff_with_delay_should_not_be_empty | ||
app_name = 'test' | ||
app_name = 'test' | ||
delay_interval = 2 | ||
data = { | ||
'id' => 123, | ||
'state' => 'active', | ||
'delay_interval' => delay_interval | ||
} | ||
|
||
Ariadne.insert_data(options: data, app_name: app_name) | ||
sleep delay_interval | ||
out = Ariadne.get_data_with_time_difference(app_name: app_name) | ||
assert_equal JSON.parse(out)[0]['id'], data['id'] | ||
end | ||
|
||
def test_get_data_with_id | ||
app_name = 'test' | ||
data = { | ||
'id' => 123, | ||
'state' => 'active' | ||
} | ||
|
||
Ariadne.insert_data(options: data, app_name: app_name) | ||
out = Ariadne.get_data(id: data['id'], app_name: app_name) | ||
assert_equal JSON.parse(out[0])['id'], data['id'] | ||
end | ||
|
||
def test_get_data_with_time_diff_with_id_without_delay_should_be_empty | ||
app_name = 'test' | ||
data = { | ||
'id' => 123, | ||
'state' => 'active' | ||
} | ||
|
||
Ariadne.insert_data(options: data, app_name: app_name) | ||
out = Ariadne.get_data_with_time_difference(id: data['id'], app_name: app_name) | ||
assert_empty JSON.parse(out) | ||
end | ||
|
||
def test_get_data_with_time_diff_with_id_with_delay_should_not_be_empty | ||
app_name = 'test' | ||
delay_interval = 2 | ||
data = { | ||
id: 123, | ||
state: 'active', | ||
app_name: app_name, | ||
delay_interval: delay_interval | ||
'id' => 123, | ||
'state' => 'active', | ||
'delay_interval' => delay_interval | ||
} | ||
|
||
Ariadne.insert_data(data) | ||
Ariadne.insert_data(options: data, app_name: app_name) | ||
sleep delay_interval | ||
out = Ariadne.get_data_with_time_difference(app_name) | ||
assert_equal JSON.parse(out)[0]['id'], data[:id] | ||
out = Ariadne.get_data_with_time_difference(id: data['id'], app_name: app_name) | ||
assert_equal JSON.parse(out)[0]['id'], data['id'] | ||
end | ||
end | ||
end |