@@ -129,7 +129,7 @@ TEST_P(TestVm, AlwaysApplyCanaryForDifferentRootID) {
129
129
// Define callbacks.
130
130
WasmHandleFactory wasm_handle_factory =
131
131
[this , vm_id, vm_config](std::string_view vm_key) -> std::shared_ptr<WasmHandleBase> {
132
- auto base_wasm = std::make_shared<WasmBase >(newVm (), vm_id, vm_config, vm_key,
132
+ auto base_wasm = std::make_shared<TestWasm >(newVm (), vm_id, vm_config, vm_key,
133
133
std::unordered_map<std::string, std::string>{},
134
134
AllowedCapabilitiesMap{});
135
135
return std::make_shared<WasmHandleBase>(base_wasm);
@@ -138,17 +138,20 @@ TEST_P(TestVm, AlwaysApplyCanaryForDifferentRootID) {
138
138
WasmHandleCloneFactory wasm_handle_clone_factory =
139
139
[this ](const std::shared_ptr<WasmHandleBase> &base_wasm_handle)
140
140
-> std::shared_ptr<WasmHandleBase> {
141
- auto wasm = std::make_shared<WasmBase >(base_wasm_handle,
141
+ auto wasm = std::make_shared<TestWasm >(base_wasm_handle,
142
142
[this ]() -> std::unique_ptr<WasmVm> { return newVm (); });
143
143
return std::make_shared<WasmHandleBase>(wasm);
144
144
};
145
145
146
146
auto canary_count = 0 ;
147
+ TestContext *root_context_in_canary = nullptr ;
147
148
WasmHandleCloneFactory wasm_handle_clone_factory_for_canary =
148
- [&canary_count, this ](const std::shared_ptr<WasmHandleBase> &base_wasm_handle)
149
+ [&canary_count, &root_context_in_canary,
150
+ this ](const std::shared_ptr<WasmHandleBase> &base_wasm_handle)
149
151
-> std::shared_ptr<WasmHandleBase> {
150
- auto wasm = std::make_shared<WasmBase>(base_wasm_handle,
151
- [this ]() -> std::unique_ptr<WasmVm> { return newVm (); });
152
+ auto wasm = std::make_shared<TestWasm>(
153
+ base_wasm_handle, [this ]() -> std::unique_ptr<WasmVm> { return newVm (); },
154
+ [&root_context_in_canary](TestContext *ctx) { root_context_in_canary = ctx; });
152
155
canary_count++;
153
156
return std::make_shared<WasmHandleBase>(wasm);
154
157
};
@@ -165,22 +168,28 @@ TEST_P(TestVm, AlwaysApplyCanaryForDifferentRootID) {
165
168
// Create a first plugin.
166
169
const auto plugin_1 = std::make_shared<PluginBase>(plugin_name, root_id_1, vm_id, engine_,
167
170
plugin_config, fail_open, plugin_key);
168
- // Create base Wasm via createWasm.
171
+ // Create a base Wasm by createWasm.
169
172
auto base_wasm_handle_1 = createWasm (vm_key, source, plugin_1, wasm_handle_factory,
170
173
wasm_handle_clone_factory_for_canary, false );
171
174
ASSERT_TRUE (base_wasm_handle_1 && base_wasm_handle_1->wasm ());
172
175
176
+ // Check if it ran for root context 1
177
+ EXPECT_TRUE (root_context_in_canary->isLogged (" onConfigure in TestRootContext1" ));
178
+
173
179
// Create a first plugin.
174
180
const auto plugin_2 = std::make_shared<PluginBase>(plugin_name, root_id_2, vm_id, engine_,
175
181
plugin_config, fail_open, plugin_key);
176
- // Create base Wasm via createWasm.
182
+ // Create a base Wasm by createWasm.
177
183
auto base_wasm_handle_2 = createWasm (vm_key, source, plugin_2, wasm_handle_factory,
178
184
wasm_handle_clone_factory_for_canary, false );
179
185
ASSERT_TRUE (base_wasm_handle_2 && base_wasm_handle_2->wasm ());
180
186
181
- // Base Wasm
187
+ // Check if it ran for root context 2
188
+ EXPECT_TRUE (root_context_in_canary->isLogged (" onConfigure in TestRootContext2" ));
189
+
190
+ // Base Wasm should be equal, because the same vm_key is used.
182
191
EXPECT_EQ (base_wasm_handle_1->wasm (), base_wasm_handle_2->wasm ());
183
- // Plugin key should be different with each other, because root_id is different.
192
+ // Plugin key should be different with each other, because root_ids are different.
184
193
EXPECT_NE (plugin_1->key (), plugin_2->key ());
185
194
// For each create Wasm, canary should be done.
186
195
EXPECT_EQ (canary_count, 2 );
0 commit comments