-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathtest_helper.exs
128 lines (103 loc) · 3.44 KB
/
test_helper.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Logger.configure(level: :info)
ExUnit.start(
exclude: [
:assigns_id_type,
:array_type,
:case_sensitive,
:modify_foreign_key_on_update,
:modify_foreign_key_on_delete,
:uses_usec,
:lock_for_update,
# NOTE: there is bug with transaction timeout, it works bt error is not returned Repo transaction function
:disconnect_on_transaction_timout,
# Note: this requires read uncommited, otherwise it is normal to lock :)
:transactions_are_not_shared_in_repo,
:with_conflict_target,
:with_conflict_ignore
]
)
Application.put_env(:ecto, :lock_for_update, "FOR UPDATE")
Application.put_env(:ecto, :primary_key_type, :id)
Application.put_env(:ecto, :async_integration_tests, false)
# Basic test repo
Code.require_file("./integration/support/types.exs", __DIR__)
Code.require_file("./integration/support/repo.exs", __DIR__)
Code.require_file("./integration/support/schemas.exs", __DIR__)
Code.require_file("./integration/support/migration.exs", __DIR__)
pool =
case System.get_env("ECTO_POOL") || "poolboy" do
"poolboy" -> DBConnection.Poolboy
"sbroker" -> DBConnection.Sojourn
end
alias Ecto.Integration.TestRepo
Application.put_env(
:ecto,
TestRepo,
filter_null_on_unique_indexes: true,
adapter: Tds.Ecto,
hostname: System.get_env("SQL_HOSTNAME") || "localhost",
username: System.get_env("SQL_USERNAME") || "sa",
password: System.get_env("SQL_PASSWORD") || "some!Password",
database: "ecto_test",
pool: Ecto.Adapters.SQL.Sandbox,
ownership_pool: pool,
# pool_size: 1, # temp fix for async tests, since they cause deadlocks
# set_transaction_isolation_level: :snapshot,
# set_allow_snapshot_isolation: :on
)
defmodule Ecto.Integration.TestRepo do
use Ecto.Integration.Repo, otp_app: :ecto
end
alias Ecto.Integration.PoolRepo
Application.put_env(
:ecto,
PoolRepo,
adapter: Tds.Ecto,
pool: pool,
hostname: System.get_env("SQL_HOSTNAME") || "localhost",
username: System.get_env("SQL_USERNAME") || "sa",
password: System.get_env("SQL_PASSWORD") || "some!Password",
database: "ecto_test",
max_restarts: 20,
max_seconds: 10,
# pool_size: 1, # temp fix for async tests, since they cause deadlocks
# set_transaction_isolation_level: :snapshot,
# set_allow_snapshot_isolation: :on
)
defmodule Ecto.Integration.PoolRepo do
use Ecto.Integration.Repo, otp_app: :ecto
def create_prefix(prefix) do
"create schema #{prefix}"
end
def drop_prefix(prefix) do
"drop schema #{prefix}"
end
end
defmodule Ecto.Integration.Case do
use ExUnit.CaseTemplate
alias Ecto.Integration.TestRepo
setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(TestRepo)
end
end
# :debugger.start()
# :int.ni(Tds.Ecto)
# :int.break(Tds.Ecto, 164)
:dbg.tracer()
:dbg.p(:all, :c)
# :dbg.tpl(Tds.Protocol, :handle_begin, :x)
# :dbg.tpl(Tds.Protocol, :handle_commit, :x)
# :dbg.tpl(Tds.Protocol, :handle_rollback, :x)
# :dbg.tpl(Tds.Protocol, :handle_prepare, :x)
# :dbg.tpl(Tds.Protocol, :handle_exec, :x)
:erlang.system_flag(:backtrace_depth, 50)
{:ok, _} = Tds.Ecto.ensure_all_started(TestRepo, :temporary)
{:ok, _} = Tds.Ecto.ensure_all_started(PoolRepo, :temporary)
_ = Tds.Ecto.storage_down(TestRepo.config())
:ok = Tds.Ecto.storage_up(TestRepo.config())
{:ok, _pid} = TestRepo.start_link()
{:ok, _pid} = PoolRepo.start_link()
:ok = Ecto.Migrator.up(TestRepo, 0, Ecto.Integration.Migration, log: false)
Ecto.Adapters.SQL.Sandbox.mode(TestRepo, :manual)
# :dbg.stop_clear()
Process.flag(:trap_exit, true)