Skip to content

Commit 7ba877e

Browse files
committed
Keep the wasm handler reference to reuse the wasm vm
1 parent 9006f57 commit 7ba877e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

test/wasm_test.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "include/proxy-wasm/wasm.h"
1616

1717
#include "gtest/gtest.h"
18+
#include <unordered_set>
1819

1920
#include "test/utility.h"
2021

@@ -177,6 +178,8 @@ TEST_P(TestVm, AlwaysApplyCanary) {
177178
// For each create Wasm, canary should be done.
178179
EXPECT_EQ(canary_count, 1);
179180

181+
std::unordered_set<std::shared_ptr<WasmHandleBase>> reference_holder;
182+
180183
for (const auto &root_id : root_ids) {
181184
for (const auto &vm_id : vm_ids) {
182185
for (const auto &vm_config : vm_configs) {
@@ -208,6 +211,10 @@ TEST_P(TestVm, AlwaysApplyCanary) {
208211
}
209212

210213
ASSERT_TRUE(wasm_handle_comp && wasm_handle_comp->wasm());
214+
// Keep the reference of wasm_handle_comp in order to utilize the WasmHandleBase
215+
// cache of createWasm. If we don't keep the reference, WasmHandleBase and VM will be
216+
// destroyed for each iteration.
217+
reference_holder.insert(wasm_handle_comp);
211218

212219
EXPECT_TRUE(TestContext::isGlobalLogged("onConfigure: " + root_id));
213220

@@ -228,10 +235,6 @@ TEST_P(TestVm, AlwaysApplyCanary) {
228235
}
229236
// For each create Wasm, canary should be done.
230237
EXPECT_EQ(canary_count, 1);
231-
232-
if (wasm_handle_comp->wasm() != wasm_handle_baseline->wasm()) {
233-
wasm_handle_comp->kill();
234-
}
235238
}
236239
}
237240
}

0 commit comments

Comments
 (0)