From 1114096a36e266c1e7a5098cd4a9c7e93c87a3c7 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Wed, 10 Jul 2019 18:11:05 -0400 Subject: [PATCH] fix fc::temp_directory usage in tester Can't have fc::temp_directory scoped to default_config() because that means once defualt_config() returns the only attempt at trying to clean up the tempdir is at that time -- way before any files are actually created. Make default_config() use an fc::temp_directory which tester already has anyways. So, once tester is destroyed that's when the fc::temp_directory falls out of scope and it can properly clean up at that point. A run through unit_test doesn't leave behind all its data files any longer. --- libraries/testing/include/eosio/testing/tester.hpp | 5 ++--- unittests/api_tests.cpp | 6 ++++-- unittests/auth_tests.cpp | 3 ++- unittests/producer_schedule_tests.cpp | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index db32a27276a..21f1ac26712 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -370,8 +370,7 @@ namespace eosio { namespace testing { } controller::config vcfg; - static controller::config default_config() { - fc::temp_directory tempdir; + static controller::config default_config(fc::temp_directory& tempdir) { controller::config vcfg; vcfg.blocks_dir = tempdir.path() / std::string("v_").append(config::default_blocks_dir_name); vcfg.state_dir = tempdir.path() / std::string("v_").append(config::default_state_dir_name); @@ -394,7 +393,7 @@ namespace eosio { namespace testing { } validating_tester(const flat_set& trusted_producers = flat_set()) { - vcfg = default_config(); + vcfg = default_config(tempdir); vcfg.trusted_producers = trusted_producers; diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index 27072862820..fb2eb7671cb 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -591,7 +591,8 @@ BOOST_FIXTURE_TEST_CASE(require_notice_tests, TESTER) { try { } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE(ram_billing_in_notify_tests) { try { - validating_tester chain( validating_tester::default_config() ); + fc::temp_directory tempdir; + validating_tester chain( validating_tester::default_config(tempdir) ); chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios ); chain.produce_blocks(2); @@ -1319,7 +1320,8 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try { } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE(more_deferred_transaction_tests) { try { - auto cfg = validating_tester::default_config(); + fc::temp_directory tempdir; + auto cfg = validating_tester::default_config(tempdir); cfg.contracts_console = true; validating_tester chain( cfg ); chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios ); diff --git a/unittests/auth_tests.cpp b/unittests/auth_tests.cpp index d5e26d96355..634e7459f46 100644 --- a/unittests/auth_tests.cpp +++ b/unittests/auth_tests.cpp @@ -371,7 +371,8 @@ BOOST_AUTO_TEST_CASE( any_auth ) { try { BOOST_AUTO_TEST_CASE(no_double_billing) { try { - validating_tester chain( validating_tester::default_config() ); + fc::temp_directory tempdir; + validating_tester chain( validating_tester::default_config(tempdir) ); chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios ); chain.produce_block(); diff --git a/unittests/producer_schedule_tests.cpp b/unittests/producer_schedule_tests.cpp index bec63376ff5..616380b7acd 100644 --- a/unittests/producer_schedule_tests.cpp +++ b/unittests/producer_schedule_tests.cpp @@ -328,7 +328,8 @@ BOOST_FIXTURE_TEST_CASE( producer_schedule_reduction, tester ) try { } FC_LOG_AND_RETHROW() BOOST_AUTO_TEST_CASE( empty_producer_schedule_has_no_effect ) try { - validating_tester c( validating_tester::default_config() ); + fc::temp_directory tempdir; + validating_tester c( validating_tester::default_config(tempdir) ); c.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios ); c.create_accounts( {N(alice),N(bob),N(carol)} );