Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Jun 19, 2023
1 parent 8e296bf commit e29fc61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 14 additions & 4 deletions test/Table_Tests/src/Database/Transaction_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ from Standard.Database.Errors import all
from Standard.Test import Test, Test_Suite, Problems
import Standard.Test.Extensions

import project.Database.Helpers.Name_Generator

type My_Error
Error

Expand All @@ -18,37 +20,44 @@ spec connection prefix =
Test.group prefix+"Transaction Support" <|
simple_table_structure = [Column_Description.Value "X" Value_Type.Integer]
Test.specify "should commit the changes after the transaction returns a regular value" <|
t1 = connection.create_table table_name=Nothing structure=simple_table_structure temporary=True
table_name = Name_Generator.random_name "transaction-test-1"
t1 = connection.create_table table_name=table_name structure=simple_table_structure temporary=True
t1.should_succeed
r1 = connection.jdbc_connection.run_within_transaction <|
t1.insert [1] . should_succeed
42
r1.should_equal 42

t1.at "X" . to_vector . should_equal [1]
connection.drop_table table_name

Test.specify "should rollback the changes after the inner action panics" <|
t1 = connection.create_table table_name=Nothing structure=simple_table_structure temporary=True
table_name = Name_Generator.random_name "transaction-test-2"
t1 = connection.create_table table_name=table_name structure=simple_table_structure temporary=True
t1.should_succeed
Test.expect_panic_with matcher=My_Error <|
connection.jdbc_connection.run_within_transaction <|
t1.insert [1] . should_succeed
Panic.throw My_Error.Error

t1.at "X" . to_vector . should_equal []
connection.drop_table table_name

Test.specify "should rollback the changes if the inner action returns a dataflow error" <|
t1 = connection.create_table table_name=Nothing structure=simple_table_structure temporary=True
table_name = Name_Generator.random_name "transaction-test-3"
t1 = connection.create_table table_name=table_name structure=simple_table_structure temporary=True
t1.should_succeed
r1 = connection.jdbc_connection.run_within_transaction <|
t1.insert [1] . should_succeed
Error.throw My_Error.Error
r1.should_fail_with My_Error

t1.at "X" . to_vector . should_equal []
connection.drop_table table_name

Test.specify "should commit the changes even if the inner action return value has warnings attached" <|
t1 = connection.create_table table_name=Nothing structure=simple_table_structure temporary=True
table_name = Name_Generator.random_name "transaction-test-4"
t1 = connection.create_table table_name=table_name structure=simple_table_structure temporary=True
t1.should_succeed
r1 = connection.jdbc_connection.run_within_transaction <|
t1.insert [1] . should_succeed
Expand All @@ -59,3 +68,4 @@ spec connection prefix =
Problems.expect_only_warning My_Error r1

t1.at "X" . to_vector . should_equal [1]
connection.drop_table table_name
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ from Standard.Database.Errors import Unsupported_Database_Operation
from Standard.Test import Problems, Test, Test_Suite
import Standard.Test.Extensions

import project.Database.Helpers.Name_Generator

spec =
connection = Database.connect (SQLite In_Memory)
make_table prefix columns =
Expand Down Expand Up @@ -104,7 +106,7 @@ spec =

Test.specify "does not support creating tables with date/time values" <|
t = Table.new [["a", [Date.now]], ["b", [Time_Of_Day.now]], ["c", [Date_Time.now]]]
r1 = t.select_into_database_table connection temporary=True
r1 = t.select_into_database_table connection table_name=(Name_Generator.random_name "date-time-table") temporary=True
r1.should_fail_with Unsupported_Database_Operation

Test.specify "should be able to infer types for all supported operations" <|
Expand Down

0 comments on commit e29fc61

Please sign in to comment.