prefab-cloud-ruby 0.24.3 → 0.24.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +78 -0
- data/Gemfile.lock +4 -4
- data/VERSION +1 -1
- data/bin/console +21 -0
- data/compile_protos.sh +6 -0
- data/lib/prefab/client.rb +25 -4
- data/lib/prefab/config_client.rb +17 -6
- data/lib/prefab/config_loader.rb +1 -1
- data/lib/prefab/config_resolver.rb +2 -4
- data/lib/prefab/config_value_wrapper.rb +18 -0
- data/lib/prefab/context.rb +22 -2
- data/lib/prefab/context_shape.rb +20 -0
- data/lib/prefab/context_shape_aggregator.rb +63 -0
- data/lib/prefab/criteria_evaluator.rb +61 -41
- data/lib/prefab/evaluated_configs_aggregator.rb +60 -0
- data/lib/prefab/evaluated_keys_aggregator.rb +41 -0
- data/lib/prefab/http_connection.rb +5 -1
- data/lib/prefab/local_config_parser.rb +13 -13
- data/lib/prefab/log_path_aggregator.rb +64 -0
- data/lib/prefab/logger_client.rb +11 -13
- data/lib/prefab/options.rb +37 -1
- data/lib/prefab/periodic_sync.rb +51 -0
- data/lib/prefab/time_helpers.rb +7 -0
- data/lib/prefab-cloud-ruby.rb +9 -2
- data/lib/prefab_pb.rb +33 -220
- data/prefab-cloud-ruby.gemspec +21 -5
- data/test/test_config_loader.rb +15 -15
- data/test/test_config_resolver.rb +102 -102
- data/test/test_config_value_unwrapper.rb +13 -13
- data/test/test_context.rb +42 -0
- data/test/test_context_shape.rb +51 -0
- data/test/test_context_shape_aggregator.rb +137 -0
- data/test/test_criteria_evaluator.rb +253 -150
- data/test/test_evaluated_configs_aggregator.rb +254 -0
- data/test/test_evaluated_keys_aggregator.rb +54 -0
- data/test/test_helper.rb +34 -2
- data/test/test_log_path_aggregator.rb +57 -0
- data/test/test_logger.rb +33 -33
- data/test/test_weighted_value_resolver.rb +2 -2
- metadata +21 -5
- data/lib/prefab/log_path_collector.rb +0 -102
- data/test/test_log_path_collector.rb +0 -58
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class TestContextShapeAggregator < Minitest::Test
|
6
|
+
DOB = Date.new
|
7
|
+
|
8
|
+
CONTEXT_1 = Prefab::Context.new({
|
9
|
+
'user' => {
|
10
|
+
'name' => 'user-name',
|
11
|
+
'email' => 'user.email',
|
12
|
+
'age' => 42.5
|
13
|
+
},
|
14
|
+
'subscription' => {
|
15
|
+
'plan' => 'advanced',
|
16
|
+
'free' => false
|
17
|
+
}
|
18
|
+
}).freeze
|
19
|
+
|
20
|
+
CONTEXT_2 = Prefab::Context.new({
|
21
|
+
'user' => {
|
22
|
+
'name' => 'other-user-name',
|
23
|
+
'dob' => DOB
|
24
|
+
},
|
25
|
+
'device' => {
|
26
|
+
'name' => 'device-name',
|
27
|
+
'os' => 'os-name',
|
28
|
+
'version' => 3
|
29
|
+
}
|
30
|
+
}).freeze
|
31
|
+
|
32
|
+
CONTEXT_3 = Prefab::Context.new({
|
33
|
+
'subscription' => {
|
34
|
+
'plan' => 'pro',
|
35
|
+
'trial' => true
|
36
|
+
}
|
37
|
+
}).freeze
|
38
|
+
|
39
|
+
def test_push
|
40
|
+
aggregator = new_aggregator(max_shapes: 9)
|
41
|
+
|
42
|
+
aggregator.push(CONTEXT_1)
|
43
|
+
aggregator.push(CONTEXT_2)
|
44
|
+
assert_equal 9, aggregator.data.size
|
45
|
+
|
46
|
+
# we've reached the limit so no more
|
47
|
+
aggregator.push(CONTEXT_3)
|
48
|
+
assert_equal 9, aggregator.data.size
|
49
|
+
|
50
|
+
assert_equal [['user', 'name', 2], ['user', 'email', 2], ['user', 'age', 4], ['subscription', 'plan', 2], ['subscription', 'free', 5], ['user', 'dob', 2], ['device', 'name', 2], ['device', 'os', 2], ['device', 'version', 1]],
|
51
|
+
aggregator.data.to_a
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_prepare_data
|
55
|
+
aggregator = new_aggregator
|
56
|
+
|
57
|
+
aggregator.push(CONTEXT_1)
|
58
|
+
aggregator.push(CONTEXT_2)
|
59
|
+
aggregator.push(CONTEXT_3)
|
60
|
+
|
61
|
+
data = aggregator.prepare_data
|
62
|
+
|
63
|
+
assert_equal %w[user subscription device], data.keys
|
64
|
+
|
65
|
+
assert_equal data['user'], {
|
66
|
+
'name' => 2,
|
67
|
+
'email' => 2,
|
68
|
+
'dob' => 2,
|
69
|
+
'age' => 4
|
70
|
+
}
|
71
|
+
|
72
|
+
assert_equal data['subscription'], {
|
73
|
+
'plan' => 2,
|
74
|
+
'trial' => 5,
|
75
|
+
'free' => 5
|
76
|
+
}
|
77
|
+
|
78
|
+
assert_equal data['device'], {
|
79
|
+
'name' => 2,
|
80
|
+
'os' => 2,
|
81
|
+
'version' => 1
|
82
|
+
}
|
83
|
+
|
84
|
+
assert_equal [], aggregator.data.to_a
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_sync
|
88
|
+
client = new_client
|
89
|
+
|
90
|
+
client.get 'some.key', 'default', CONTEXT_1
|
91
|
+
client.get 'some.key', 'default', CONTEXT_2
|
92
|
+
client.get 'some.key', 'default', CONTEXT_3
|
93
|
+
|
94
|
+
requests = wait_for_post_requests(client) do
|
95
|
+
client.context_shape_aggregator.send(:sync)
|
96
|
+
end
|
97
|
+
|
98
|
+
assert_equal [
|
99
|
+
[
|
100
|
+
'/api/v1/context-shapes',
|
101
|
+
PrefabProto::ContextShapes.new(shapes: [
|
102
|
+
PrefabProto::ContextShape.new(
|
103
|
+
name: 'user', field_types: {
|
104
|
+
'age' => 4, 'dob' => 2, 'email' => 2, 'name' => 2
|
105
|
+
}
|
106
|
+
),
|
107
|
+
PrefabProto::ContextShape.new(
|
108
|
+
name: 'subscription', field_types: {
|
109
|
+
'plan' => 2, 'free' => 5, 'trial' => 5
|
110
|
+
}
|
111
|
+
),
|
112
|
+
PrefabProto::ContextShape.new(
|
113
|
+
name: 'device', field_types: {
|
114
|
+
'version' => 1, 'os' => 2, 'name' => 2
|
115
|
+
}
|
116
|
+
)
|
117
|
+
])
|
118
|
+
]
|
119
|
+
], requests
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def new_client(overrides = {})
|
125
|
+
super(**{
|
126
|
+
prefab_datasources: Prefab::Options::DATASOURCES::ALL,
|
127
|
+
initialization_timeout_sec: 0,
|
128
|
+
on_init_failure: Prefab::Options::ON_INITIALIZATION_FAILURE::RETURN,
|
129
|
+
api_key: '123-development-yourapikey-SDK',
|
130
|
+
shape_sync_interval: 1000 # we'll trigger sync manually in our test
|
131
|
+
}.merge(overrides))
|
132
|
+
end
|
133
|
+
|
134
|
+
def new_aggregator(max_shapes: 1000)
|
135
|
+
Prefab::ContextShapeAggregator.new(client: new_client, sync_interval: 1000, max_shapes: max_shapes)
|
136
|
+
end
|
137
|
+
end
|