|
37 | 37 | assert_equal("storage/db/tenanted/foo/main.sqlite3", config.database_path_for("foo")) |
38 | 38 | end |
39 | 39 |
|
| 40 | + test "parallel test workers have unique files" do |
| 41 | + config.test_worker_id = 99 |
| 42 | + |
| 43 | + assert_equal("storage/db/tenanted/foo/main.sqlite3_99", config.database_path_for("foo")) |
| 44 | + end |
| 45 | + |
40 | 46 | test "raises if the tenant name contains a path separator" do |
41 | 47 | assert_raises(ActiveRecord::Tenanted::BadTenantNameError) { config.database_path_for("foo/bar") } |
42 | 48 | end |
|
50 | 56 | test "returns all tenants" do |
51 | 57 | Dir.chdir(dir) do |
52 | 58 | [ "foo", "bar", "baz" ].each do |tenant| |
53 | | - FileUtils.mkdir_p("storage/db/tenanted/#{tenant}") |
54 | | - FileUtils.touch("storage/db/tenanted/#{tenant}/main.sqlite3") |
| 59 | + path = config.database_path_for(tenant) |
| 60 | + FileUtils.mkdir_p(File.dirname(path)) |
| 61 | + FileUtils.touch(path) |
| 62 | + end |
| 63 | + |
| 64 | + assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + test "parallel test worker returns all tenants" do |
| 69 | + config.test_worker_id = 99 |
| 70 | + |
| 71 | + Dir.chdir(dir) do |
| 72 | + [ "foo", "bar", "baz" ].each do |tenant| |
| 73 | + path = config.database_path_for(tenant) |
| 74 | + FileUtils.mkdir_p(File.dirname(path)) |
| 75 | + FileUtils.touch(path) |
55 | 76 | end |
56 | 77 |
|
57 | 78 | assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
|
68 | 89 | assert_equal("#{dir}/storage/db/tenanted/foo/main.sqlite3", config.database_path_for("foo")) |
69 | 90 | end |
70 | 91 |
|
| 92 | + test "parallel test workers have unique files" do |
| 93 | + config.test_worker_id = 99 |
| 94 | + |
| 95 | + assert_equal("file:#{dir}/storage/db/tenanted/foo/main.sqlite3_99", config.database_for("foo")) |
| 96 | + assert_equal("#{dir}/storage/db/tenanted/foo/main.sqlite3_99", config.database_path_for("foo")) |
| 97 | + end |
| 98 | + |
71 | 99 | test "returns all tenants" do |
72 | 100 | Dir.chdir(dir) do |
73 | 101 | [ "foo", "bar", "baz" ].each do |tenant| |
74 | | - FileUtils.mkdir_p("storage/db/tenanted/#{tenant}") |
75 | | - FileUtils.touch("storage/db/tenanted/#{tenant}/main.sqlite3") |
| 102 | + path = config.database_path_for(tenant) |
| 103 | + FileUtils.mkdir_p(File.dirname(path)) |
| 104 | + FileUtils.touch(path) |
76 | 105 | end |
77 | 106 | end |
78 | 107 |
|
79 | 108 | assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
80 | 109 | end |
| 110 | + |
| 111 | + test "parallel test worker returns all tenants" do |
| 112 | + config.test_worker_id = 99 |
| 113 | + |
| 114 | + Dir.chdir(dir) do |
| 115 | + [ "foo", "bar", "baz" ].each do |tenant| |
| 116 | + path = config.database_path_for(tenant) |
| 117 | + FileUtils.mkdir_p(File.dirname(path)) |
| 118 | + FileUtils.touch(path) |
| 119 | + end |
| 120 | + |
| 121 | + assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
| 122 | + end |
| 123 | + end |
81 | 124 | end |
82 | 125 |
|
83 | 126 | describe "absolute URI with query params" do |
|
89 | 132 | assert_equal("#{dir}/storage/db/tenanted/foo/main.sqlite3", config.database_path_for("foo")) |
90 | 133 | end |
91 | 134 |
|
| 135 | + test "parallel test workers have unique files" do |
| 136 | + config.test_worker_id = 99 |
| 137 | + |
| 138 | + assert_equal("file:#{dir}/storage/db/tenanted/foo/main.sqlite3_99?vfs=unix-dotfile", config.database_for("foo")) |
| 139 | + assert_equal("#{dir}/storage/db/tenanted/foo/main.sqlite3_99", config.database_path_for("foo")) |
| 140 | + end |
| 141 | + |
92 | 142 | test "returns all tenants" do |
93 | 143 | Dir.chdir(dir) do |
94 | 144 | [ "foo", "bar", "baz" ].each do |tenant| |
95 | | - FileUtils.mkdir_p("storage/db/tenanted/#{tenant}") |
96 | | - FileUtils.touch("storage/db/tenanted/#{tenant}/main.sqlite3") |
| 145 | + path = config.database_path_for(tenant) |
| 146 | + FileUtils.mkdir_p(File.dirname(path)) |
| 147 | + FileUtils.touch(path) |
97 | 148 | end |
98 | 149 | end |
99 | 150 |
|
100 | 151 | assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
101 | 152 | end |
| 153 | + |
| 154 | + test "parallel test worker returns all tenants" do |
| 155 | + config.test_worker_id = 99 |
| 156 | + |
| 157 | + Dir.chdir(dir) do |
| 158 | + [ "foo", "bar", "baz" ].each do |tenant| |
| 159 | + path = config.database_path_for(tenant) |
| 160 | + FileUtils.mkdir_p(File.dirname(path)) |
| 161 | + FileUtils.touch(path) |
| 162 | + end |
| 163 | + |
| 164 | + assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
| 165 | + end |
| 166 | + end |
102 | 167 | end |
103 | 168 |
|
104 | 169 | describe "relative URI" do |
|
110 | 175 | assert_equal("storage/db/tenanted/foo/main.sqlite3", config.database_path_for("foo")) |
111 | 176 | end |
112 | 177 |
|
| 178 | + test "parallel test workers have unique files" do |
| 179 | + config.test_worker_id = 99 |
| 180 | + |
| 181 | + assert_equal("file:storage/db/tenanted/foo/main.sqlite3_99", config.database_for("foo")) |
| 182 | + assert_equal("storage/db/tenanted/foo/main.sqlite3_99", config.database_path_for("foo")) |
| 183 | + end |
| 184 | + |
113 | 185 | test "returns all tenants" do |
114 | 186 | Dir.chdir(dir) do |
115 | 187 | [ "foo", "bar", "baz" ].each do |tenant| |
116 | | - FileUtils.mkdir_p("storage/db/tenanted/#{tenant}") |
117 | | - FileUtils.touch("storage/db/tenanted/#{tenant}/main.sqlite3") |
| 188 | + path = config.database_path_for(tenant) |
| 189 | + FileUtils.mkdir_p(File.dirname(path)) |
| 190 | + FileUtils.touch(path) |
| 191 | + end |
| 192 | + |
| 193 | + assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + test "parallel test worker returns all tenants" do |
| 198 | + config.test_worker_id = 99 |
| 199 | + |
| 200 | + Dir.chdir(dir) do |
| 201 | + [ "foo", "bar", "baz" ].each do |tenant| |
| 202 | + path = config.database_path_for(tenant) |
| 203 | + FileUtils.mkdir_p(File.dirname(path)) |
| 204 | + FileUtils.touch(path) |
118 | 205 | end |
119 | 206 |
|
120 | 207 | assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
|
131 | 218 | assert_equal("storage/db/tenanted/foo/main.sqlite3", config.database_path_for("foo")) |
132 | 219 | end |
133 | 220 |
|
| 221 | + test "parallel test workers have unique files" do |
| 222 | + config.test_worker_id = 99 |
| 223 | + |
| 224 | + assert_equal("file:storage/db/tenanted/foo/main.sqlite3_99?vfs=unix-dotfile", config.database_for("foo")) |
| 225 | + assert_equal("storage/db/tenanted/foo/main.sqlite3_99", config.database_path_for("foo")) |
| 226 | + end |
| 227 | + |
134 | 228 | test "returns all tenants" do |
135 | 229 | Dir.chdir(dir) do |
136 | 230 | [ "foo", "bar", "baz" ].each do |tenant| |
|
141 | 235 | assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
142 | 236 | end |
143 | 237 | end |
| 238 | + |
| 239 | + test "parallel test worker returns all tenants" do |
| 240 | + config.test_worker_id = 99 |
| 241 | + |
| 242 | + Dir.chdir(dir) do |
| 243 | + [ "foo", "bar", "baz" ].each do |tenant| |
| 244 | + path = config.database_path_for(tenant) |
| 245 | + FileUtils.mkdir_p(File.dirname(path)) |
| 246 | + FileUtils.touch(path) |
| 247 | + end |
| 248 | + |
| 249 | + assert_equal(Set.new(config.tenants), Set.new([ "foo", "bar", "baz" ])) |
| 250 | + end |
| 251 | + end |
144 | 252 | end |
145 | 253 | end |
146 | 254 |
|
|
0 commit comments