From 1c87b8f467050ad595cbdbe5e8587745ece7c26e Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Wed, 31 Jan 2024 18:04:37 +0100 Subject: [PATCH 1/4] Fix teardown in SQLite File spec --- test/Table_Tests/src/Database/SQLite_Spec.enso | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/Table_Tests/src/Database/SQLite_Spec.enso b/test/Table_Tests/src/Database/SQLite_Spec.enso index e6960d2a2195..09d60f6f00c9 100644 --- a/test/Table_Tests/src/Database/SQLite_Spec.enso +++ b/test/Table_Tests/src/Database/SQLite_Spec.enso @@ -41,7 +41,7 @@ type Metadata_Data tinfo self = self.data.at 1 t self = self.data.at 2 - setup create_connection_func = + setup create_connection_func = Metadata_Data.Value <| connection = create_connection_func Nothing tinfo = Name_Generator.random_name "Tinfo" connection.execute_update 'CREATE TABLE "'+tinfo+'" ("strs" VARCHAR, "ints" INTEGER, "bools" BOOLEAN, "reals" REAL)' @@ -51,10 +51,11 @@ type Metadata_Data row3 = ["def", 42, True, 1.4] Panic.rethrow <| t.update_rows (Table.from_rows ["strs", "ints", "bools", "reals"] [row1, row2, row3]) update_action=Update_Action.Insert - Metadata_Data.Value [connection, tinfo, t] + [connection, tinfo, t] teardown self = self.connection.drop_table self.t.name + self.connection.drop_table self.tinfo self.connection.close @@ -80,6 +81,9 @@ type Tables_And_Table_Types_Data [connection, tinfo, vinfo, temporary_table] teardown self = + self.connection.drop_table self.tinfo + self.connection.drop_table self.vinfo + self.connection.drop_table self.temporary_table self.connection.close From f4163b790d65bb1db5caacef8e9a7f69b0e85997 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 1 Feb 2024 10:09:08 +0100 Subject: [PATCH 2/4] Delete SQLite file before setup --- test/Table_Tests/src/Database/SQLite_Spec.enso | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Table_Tests/src/Database/SQLite_Spec.enso b/test/Table_Tests/src/Database/SQLite_Spec.enso index 09d60f6f00c9..5530d934d728 100644 --- a/test/Table_Tests/src/Database/SQLite_Spec.enso +++ b/test/Table_Tests/src/Database/SQLite_Spec.enso @@ -370,6 +370,7 @@ create_inmem_connection = create_file_connection file = + file.delete_if_exists connection = Database.connect (SQLite file) connection.execute_update 'CREATE TABLE "Dummy" ("strs" VARCHAR, "ints" INTEGER, "bools" BOOLEAN, "reals" REAL)' connection From c007c4ee5cc7d1d2584e9cc16ac37a76d9bfb971 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Thu, 1 Feb 2024 16:08:33 +0100 Subject: [PATCH 3/4] Revert "Delete SQLite file before setup" This reverts commit f4163b790d65bb1db5caacef8e9a7f69b0e85997. --- test/Table_Tests/src/Database/SQLite_Spec.enso | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Table_Tests/src/Database/SQLite_Spec.enso b/test/Table_Tests/src/Database/SQLite_Spec.enso index 5530d934d728..09d60f6f00c9 100644 --- a/test/Table_Tests/src/Database/SQLite_Spec.enso +++ b/test/Table_Tests/src/Database/SQLite_Spec.enso @@ -370,7 +370,6 @@ create_inmem_connection = create_file_connection file = - file.delete_if_exists connection = Database.connect (SQLite file) connection.execute_update 'CREATE TABLE "Dummy" ("strs" VARCHAR, "ints" INTEGER, "bools" BOOLEAN, "reals" REAL)' connection From bcfcdbd61ef2d5eca38c2e116cdae10d5ed503e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Wa=C5=9Bko?= Date: Mon, 5 Feb 2024 11:21:06 +0100 Subject: [PATCH 4/4] clean db file on first access --- .../Table_Tests/src/Database/SQLite_Spec.enso | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/test/Table_Tests/src/Database/SQLite_Spec.enso b/test/Table_Tests/src/Database/SQLite_Spec.enso index 09d60f6f00c9..29bef3f4e23d 100644 --- a/test/Table_Tests/src/Database/SQLite_Spec.enso +++ b/test/Table_Tests/src/Database/SQLite_Spec.enso @@ -359,33 +359,36 @@ supported_replace_params = e = [Replace_Params.Value Text Case_Sensitivity.Default False, Replace_Params.Value Text Case_Sensitivity.Sensitive False, Replace_Params.Value Text Case_Sensitivity.Default True, Replace_Params.Value Text Case_Sensitivity.Sensitive True, Replace_Params.Value Text Case_Sensitivity.Insensitive True] Set.from_vector e -backing_file = - transient_dir = enso_project.data / "transient" - assert transient_dir.exists ("There should be .gitignore file in the " + transient_dir.path + " directory") - transient_dir / "sqlite_test.db" +## Reference to the database file that ensures the first test that uses it will + clean any leftover files from earlier runs. +type Database_File + Value ~file + create = Database_File.Value <| + transient_dir = enso_project.data / "transient" + assert transient_dir.exists ("The directory " + transient_dir.path + " should exist (ensured by containing a `.gitignore` file).") + f = transient_dir / "sqlite_test.db" + f.delete_if_exists + f create_inmem_connection = Database.connect (SQLite In_Memory) - create_file_connection file = connection = Database.connect (SQLite file) connection.execute_update 'CREATE TABLE "Dummy" ("strs" VARCHAR, "ints" INTEGER, "bools" BOOLEAN, "reals" REAL)' connection - type File_Connection Value ~file - setup = File_Connection.Value <| - tmp_file = backing_file - con = create_file_connection backing_file + setup db_file:Database_File = File_Connection.Value <| + tmp_file = db_file.file + con = create_file_connection tmp_file con.close assert tmp_file.exists tmp_file - teardown self = assert self.file.exists self.file.delete @@ -393,10 +396,11 @@ type File_Connection add_specs suite_builder = in_file_prefix = "[SQLite File] " + database_file = Database_File.create - sqlite_spec suite_builder in_file_prefix (_ -> create_file_connection backing_file) - Transaction_Spec.add_specs suite_builder (_ -> create_file_connection backing_file) in_file_prefix - Upload_Spec.add_specs suite_builder (_ -> create_file_connection backing_file) in_file_prefix + sqlite_spec suite_builder in_file_prefix (_ -> create_file_connection database_file.file) + Transaction_Spec.add_specs suite_builder (_ -> create_file_connection database_file.file) in_file_prefix + Upload_Spec.add_specs suite_builder (_ -> create_file_connection database_file.file) in_file_prefix in_memory_prefix = "[SQLite In-Memory] " sqlite_spec suite_builder in_memory_prefix (_ -> create_inmem_connection) @@ -406,7 +410,7 @@ add_specs suite_builder = SQLite_Type_Mapping_Spec.add_specs suite_builder suite_builder.group "SQLite_Format should allow connecting to SQLite files" group_builder-> - data = File_Connection.setup + data = File_Connection.setup database_file group_builder.teardown <| data.teardown