@@ -162,33 +162,28 @@ TEST_P(TestVm, RecoverCrashedThreadLocalWasm) {
162
162
// Create a thread local plugin.
163
163
auto thread_local_plugin = getOrCreateThreadLocalPlugin (
164
164
base_wasm_handle, plugin, wasm_handle_clone_factory, plugin_handle_factory);
165
+ auto old_wasm_ptr = thread_local_plugin->wasm ();
165
166
// Cause runtime crash.
166
167
thread_local_plugin->wasm ()->wasm_vm ()->fail (FailState::RuntimeError, " runtime error msg" );
167
168
ASSERT_TRUE (thread_local_plugin->wasm ()->isFailed ());
168
169
169
- auto old_wasm_ptr = thread_local_plugin->wasm ();
170
170
// do recover.
171
- std::shared_ptr<PluginHandleBase> new_thread_local_plugin;
172
- ASSERT_TRUE (thread_local_plugin->doRecover (new_thread_local_plugin));
171
+ ASSERT_TRUE (thread_local_plugin->doRecover ());
173
172
// Verify recover success.
174
- ASSERT_FALSE (new_thread_local_plugin->wasm ()->isFailed ());
175
- // Verify handle is reused.
176
- ASSERT_EQ (new_thread_local_plugin->wasmHandle ().get (), thread_local_plugin->wasmHandle ().get ());
177
- ASSERT_EQ (new_thread_local_plugin.get (), thread_local_plugin.get ());
173
+ ASSERT_FALSE (thread_local_plugin->wasm ()->isFailed ());
178
174
// Verify the pointer to WasmBase is different from the crashed one.
179
- ASSERT_NE (new_thread_local_plugin ->wasm (), old_wasm_ptr);
175
+ ASSERT_NE (thread_local_plugin ->wasm (), old_wasm_ptr);
180
176
177
+ old_wasm_ptr = thread_local_plugin->wasm ();
181
178
// Cause runtime crash again.
182
- new_thread_local_plugin->wasm ()->wasm_vm ()->fail (FailState::RuntimeError, " runtime error msg" );
183
- ASSERT_TRUE (new_thread_local_plugin->wasm ()->isFailed ());
184
- old_wasm_ptr = new_thread_local_plugin->wasm ();
179
+ thread_local_plugin->wasm ()->wasm_vm ()->fail (FailState::RuntimeError, " runtime error msg" );
180
+ ASSERT_TRUE (thread_local_plugin->wasm ()->isFailed ());
185
181
// Do recover again.
186
- std::shared_ptr<PluginHandleBase> new_thread_local_plugin2;
187
- ASSERT_TRUE (new_thread_local_plugin->doRecover (new_thread_local_plugin2));
182
+ ASSERT_TRUE (thread_local_plugin->doRecover ());
188
183
// Verify recover again success.
189
- ASSERT_FALSE (new_thread_local_plugin2 ->wasm ()->isFailed ());
184
+ ASSERT_FALSE (thread_local_plugin ->wasm ()->isFailed ());
190
185
// Verify the pointer to WasmBase is different from the crashed one.
191
- ASSERT_NE (new_thread_local_plugin2 ->wasm (), old_wasm_ptr);
186
+ ASSERT_NE (thread_local_plugin ->wasm (), old_wasm_ptr);
192
187
193
188
// This time, create another thread local plugin with *different* plugin key for the same vm_key.
194
189
// This one should reuse the recovered VM.
@@ -199,53 +194,53 @@ TEST_P(TestVm, RecoverCrashedThreadLocalWasm) {
199
194
ASSERT_TRUE (thread_local_plugin_another && thread_local_plugin_another->plugin ());
200
195
ASSERT_FALSE (thread_local_plugin_another->wasm ()->isFailed ());
201
196
// Verify the pointer to WasmBase is same with recovered one
202
- ASSERT_EQ (thread_local_plugin_another->wasm (), new_thread_local_plugin2 ->wasm ());
197
+ ASSERT_EQ (thread_local_plugin_another->wasm (), thread_local_plugin ->wasm ());
203
198
199
+ old_wasm_ptr = thread_local_plugin->wasm ();
204
200
// Cause runtime crash again.
205
- new_thread_local_plugin2 ->wasm ()->wasm_vm ()->fail (FailState::RuntimeError, " runtime error msg" );
206
- ASSERT_TRUE (new_thread_local_plugin2 ->wasm ()->isFailed ());
201
+ thread_local_plugin ->wasm ()->wasm_vm ()->fail (FailState::RuntimeError, " runtime error msg" );
202
+ ASSERT_TRUE (thread_local_plugin ->wasm ()->isFailed ());
207
203
// Create another thread local plugin with *different* plugin key before recover.
208
204
// This one also should not end up using the failed VM.
209
205
auto thread_local_plugin_another2 = getOrCreateThreadLocalPlugin (
210
206
base_wasm_handle, plugin_another, wasm_handle_clone_factory, plugin_handle_factory);
211
207
ASSERT_TRUE (thread_local_plugin_another2 && thread_local_plugin_another2->plugin ());
212
208
ASSERT_FALSE (thread_local_plugin_another2->wasm ()->isFailed ());
213
209
// Verify the pointer to WasmBase is different from the failed one.
214
- ASSERT_NE (thread_local_plugin_another2->wasm (), new_thread_local_plugin2 ->wasm ());
210
+ ASSERT_NE (thread_local_plugin_another2->wasm (), thread_local_plugin ->wasm ());
215
211
// Do recover again.
216
- std::shared_ptr<PluginHandleBase> new_thread_local_plugin3;
217
- ASSERT_TRUE (new_thread_local_plugin2->doRecover (new_thread_local_plugin3));
218
- // Recover should reuse the VM already created by the new plugin
219
- ASSERT_EQ (new_thread_local_plugin3->wasm (), thread_local_plugin_another2->wasm ());
212
+ ASSERT_TRUE (thread_local_plugin->doRecover ());
213
+ // Verify the pointer to WasmBase is different from the crashed one.
214
+ ASSERT_NE (thread_local_plugin->wasm (), old_wasm_ptr);
220
215
216
+ old_wasm_ptr = thread_local_plugin_another2->wasm ();
221
217
// Cause the another plugin with same vm_key crash.
222
218
thread_local_plugin_another2->wasm ()->wasm_vm ()->fail (FailState::RuntimeError,
223
219
" runtime error msg" );
224
220
ASSERT_TRUE (thread_local_plugin_another2->wasm ()->isFailed ());
225
- old_wasm_ptr = thread_local_plugin_another2->wasm ();
226
221
// Do recover again
227
- std::shared_ptr<PluginHandleBase> new_thread_local_plugin_another2;
228
- ASSERT_TRUE (thread_local_plugin_another2->doRecover (new_thread_local_plugin_another2));
229
- ASSERT_EQ (thread_local_plugin_another2->wasm (), new_thread_local_plugin_another2->wasm ());
222
+ ASSERT_TRUE (thread_local_plugin_another2->doRecover ());
230
223
// Verify the pointer to WasmBase is different from the crashed one.
231
- ASSERT_NE (new_thread_local_plugin_another2 ->wasm (), old_wasm_ptr);
224
+ ASSERT_NE (thread_local_plugin_another2 ->wasm (), old_wasm_ptr);
232
225
226
+ old_wasm_ptr = thread_local_plugin_another2->wasm ();
233
227
// Cause the another plugin crash again
234
- new_thread_local_plugin_another2 ->wasm ()->wasm_vm ()->fail (FailState::RuntimeError,
235
- " runtime error msg" );
236
- ASSERT_TRUE (new_thread_local_plugin_another2 ->wasm ()->isFailed ());
228
+ thread_local_plugin_another2 ->wasm ()->wasm_vm ()->fail (FailState::RuntimeError,
229
+ " runtime error msg" );
230
+ ASSERT_TRUE (thread_local_plugin_another2 ->wasm ()->isFailed ());
237
231
// Create thread local plugin with same plugin key
238
- auto new_thread_local_plugin_another3 = getOrCreateThreadLocalPlugin (
232
+ auto thread_local_plugin_another3 = getOrCreateThreadLocalPlugin (
239
233
base_wasm_handle, plugin_another, wasm_handle_clone_factory, plugin_handle_factory);
240
- ASSERT_TRUE (new_thread_local_plugin_another3 && new_thread_local_plugin_another3 ->plugin ());
241
- ASSERT_FALSE (new_thread_local_plugin_another3 ->wasm ()->isFailed ());
234
+ ASSERT_TRUE (thread_local_plugin_another3 && thread_local_plugin_another3 ->plugin ());
235
+ ASSERT_FALSE (thread_local_plugin_another3 ->wasm ()->isFailed ());
242
236
// Verify the pointer to WasmBase is different from the failed one.
243
- ASSERT_NE (new_thread_local_plugin_another3 ->wasm (), new_thread_local_plugin_another2 ->wasm ());
237
+ ASSERT_NE (thread_local_plugin_another3 ->wasm (), thread_local_plugin_another2 ->wasm ());
244
238
// Do recover again.
245
- std::shared_ptr<PluginHandleBase> new_thread_local_plugin_another4;
246
- ASSERT_TRUE (new_thread_local_plugin_another2->doRecover (new_thread_local_plugin_another4));
247
- // Recover should reuse the plugin handle
248
- ASSERT_EQ (new_thread_local_plugin_another4, new_thread_local_plugin_another3);
239
+ ASSERT_TRUE (thread_local_plugin_another2->doRecover ());
240
+ // Recover should not reuse the plugin handle
241
+ ASSERT_NE (thread_local_plugin_another2, thread_local_plugin_another3);
242
+ // Recover shoud reuse the wasm handle
243
+ ASSERT_EQ (thread_local_plugin_another2->wasm (), thread_local_plugin_another3->wasm ());
249
244
}
250
245
251
246
// Tests the canary is always applied when making a call `createWasm`
0 commit comments