OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace-rocks commits / 9182c3f

Remove some of the excessive resetting
9182c3f4f07722736ea170be3f6b7a54fb02ac82
by Linas Vepstas <linasvepstas@gmail.com> · 2026-01-18T23:11:24.000Z

Changed files (1) +35 -49

tests/persist/monospace/MonoBasicSaveUTest.cxxtest +35 -49
……@@ -223,12 +223,7 @@ void MonoBasicSaveUTest::single_atom_save_restore(std::string id)
223223 atomCompare(l, hl, "Single link save-restore");
224224 printf("Done fetching single link\n");
225225
226 // Close the store and clean up database for next iteration.
227 store->setValue(as->add_node(PREDICATE_NODE, "*-erase-*"), createVoidValue());
228 store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue());
229 store.reset();
230 hsn = Handle::UNDEFINED;
231 as.reset();
226 store->erase();
232227}
233228
234229// ============================================================
……@@ -364,12 +359,7 @@ void MonoBasicSaveUTest::test_fresh_atom(void)
364359 if (he) printf("Got %s\n", he->to_string().c_str());
365360 atomCompare(le, he, "Empty Fresh");
366361
367 // Close the store and clean up database for next test.
368 store->setValue(as->add_node(PREDICATE_NODE, "*-erase-*"), createVoidValue());
369 store->setValue(as->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue());
370 store.reset();
371 hsn = Handle::UNDEFINED;
372 as.reset();
362 store->erase();
373363
374364 logger().debug("END TEST: %s", __FUNCTION__);
375365}
……@@ -378,45 +368,46 @@ void MonoBasicSaveUTest::test_table()
378368{
379369 logger().debug("BEGIN TEST: %s", __FUNCTION__);
380370
381 AtomSpacePtr as1 = createAtomSpace();
382 Handle hsn = as1->add_node(MONO_STORAGE_NODE, std::string(uri));
383 StorageNodePtr store = StorageNodeCast(hsn);
384 store->setValue(as1->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue());
385 if (!store->connected())
371 size_t num_stored;
372
373 // Use scope block to ensure as1 is destroyed before as2 opens
386374 {
387 logger().debug("test_table: cannot connect to db");
388 return;
389 }
375 AtomSpacePtr as1 = createAtomSpace();
376 Handle hsn = as1->add_node(MONO_STORAGE_NODE, std::string(uri));
377 StorageNodePtr store = StorageNodeCast(hsn);
378 store->setValue(as1->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue());
379 if (!store->connected())
380 {
381 logger().debug("test_table: cannot connect to db");
382 return;
383 }
390384
391 int idx = 0;
392 add_to_table(idx++, as1.get(), "AA-aa-wow ");
393 add_to_table(idx++, as1.get(), "BB-bb-wow ");
394 add_to_table(idx++, as1.get(), "CC-cc-wow ");
395 add_to_table(idx++, as1.get(), "DD-dd-wow ");
396 add_to_table(idx++, as1.get(), "EE-ee-wow ");
385 int idx = 0;
386 add_to_table(idx++, as1.get(), "AA-aa-wow ");
387 add_to_table(idx++, as1.get(), "BB-bb-wow ");
388 add_to_table(idx++, as1.get(), "CC-cc-wow ");
389 add_to_table(idx++, as1.get(), "DD-dd-wow ");
390 add_to_table(idx++, as1.get(), "EE-ee-wow ");
397391
398 store->store_atomspace();
399 // Subtract 2 for the MonoStorageNode and *-open-* PredicateNode
400 size_t num_stored = as1->get_size() - 2;
392 store->store_atomspace();
393 // Subtract 2 for the MonoStorageNode and *-open-* PredicateNode
394 num_stored = as1->get_size() - 2;
401395#ifdef DOPRT
402 HandleSeq hset;
403 as1->get_handles_by_type(hset, ATOM, true, false);
404 for (auto h: hset) {
405 printf("Store table has %s\n", h->to_string().c_str());
406 }
396 HandleSeq hset;
397 as1->get_handles_by_type(hset, ATOM, true, false);
398 for (auto h: hset) {
399 printf("Store table has %s\n", h->to_string().c_str());
400 }
407401#endif
408402
409 // Explicitly close the store before resetting handles.
410 store->setValue(as1->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue());
411 store.reset();
412 hsn = Handle::UNDEFINED;
413 as1.reset();
414 printf("Done storing table; size=%lu\n", num_stored);
403 printf("Done storing table; size=%lu\n", num_stored);
404 }
405 // as1 goes out of scope here, storage is closed automatically
415406
416407 // Reopen connection, and load the atom table.
417408 AtomSpacePtr as2 = createAtomSpace();
418 hsn = as2->add_node(MONO_STORAGE_NODE, std::string(uri));
419 store = StorageNodeCast(hsn);
409 Handle hsn = as2->add_node(MONO_STORAGE_NODE, std::string(uri));
410 StorageNodePtr store = StorageNodeCast(hsn);
420411 store->setValue(as2->add_node(PREDICATE_NODE, "*-open-*"), createVoidValue());
421412 TSM_ASSERT("Not connected to database", store->connected());
422413
……@@ -430,19 +421,14 @@ void MonoBasicSaveUTest::test_table()
430421 // and (PredicateNode "*-IsKeyFlag-*")
431422 TSM_ASSERT("Wrong number of atoms fetched", num_fetched == num_stored+2);
432423
433 idx = 0;
424 int idx = 0;
434425 check_table(idx++, as2.get(), "aaa ");
435426 check_table(idx++, as2.get(), "bbb ");
436427 check_table(idx++, as2.get(), "ccc ");
437428 check_table(idx++, as2.get(), "ddd ");
438429 check_table(idx++, as2.get(), "eee ");
439430
440 // Close the store and clean up database.
441 store->setValue(as2->add_node(PREDICATE_NODE, "*-erase-*"), createVoidValue());
442 store->setValue(as2->add_node(PREDICATE_NODE, "*-close-*"), createVoidValue());
443 store.reset();
444 hsn = Handle::UNDEFINED;
445 as2.reset();
431 store->erase();
446432
447433 logger().debug("END TEST: %s", __FUNCTION__);
448434}