Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
1dd3ee47
Commit
1dd3ee47
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Fix sync database test random failures
parent
36e3d8af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/sync_database_test.clj
+37
-35
37 additions, 35 deletions
test/metabase/sync_database_test.clj
with
37 additions
and
35 deletions
test/metabase/sync_database_test.clj
+
37
−
35
View file @
1dd3ee47
...
...
@@ -10,7 +10,8 @@
[
table
:refer
[
Table
]])
[
metabase.sync-database
:refer
:all
]
(
metabase.test
[
data
:refer
:all
]
[
util
:refer
[
resolve-private-vars
]
:as
tu
])))
[
util
:refer
[
resolve-private-vars
]
:as
tu
])
[
metabase.util
:as
u
]))
(
def
^
:private
^
:const
sync-test-tables
{
"movie"
{
:name
"movie"
...
...
@@ -132,12 +133,12 @@
:name
"studio"
:display_name
"Studio"
:base_type
:type/Text
})]})]
(
tu/with-temp
Database
[
fake-
db
{
:engine
:sync-test
}]
(
sync-database!
fake-
db
)
(
tu/with-temp
Database
[
db
{
:engine
:sync-test
}]
(
sync-database!
db
)
;; we are purposely running the sync twice to test for possible logic issues which only manifest
;; on resync of a database, such as adding tables that already exist or duplicating fields
(
sync-database!
fake-
db
)
(
mapv
table-details
(
db/select
Table,
:db_id
(
:id
fake-
db
)
,
{
:order-by
[
:name
]}))))
(
sync-database!
db
)
(
mapv
table-details
(
db/select
Table,
:db_id
(
u/get-id
db
)
,
{
:order-by
[
:name
]}))))
;; ## SYNC TABLE
...
...
@@ -162,14 +163,14 @@
:name
"title"
:display_name
"Title"
:base_type
:type/Text
})]})
(
tu/with-temp*
[
Database
[
fake-db
{
:engine
:sync-test
}]
RawTable
[
{
raw-table
-id
:id
}
{
:database_id
(
:id
fake-
db
)
,
:name
"movie"
,
:schema
"default"
}]
Table
[
fake-
table
{
:raw_table_id
raw-table
-id
:name
"movie"
:schema
"default"
:db_id
(
:id
fake-
db
)}]]
(
sync-table!
fake-
table
)
(
table-details
(
Table
(
:id
fake-
table
)))))
(
tu/with-temp*
[
Database
[
db
{
:engine
:sync-test
}]
RawTable
[
raw-table
{
:database_id
(
u/get-id
db
)
,
:name
"movie"
,
:schema
"default"
}]
Table
[
table
{
:raw_table_id
(
u/get-id
raw-table
)
:name
"movie"
:schema
"default"
:db_id
(
u/get-id
db
)}]]
(
sync-table!
table
)
(
table-details
(
Table
(
:id
table
)))))
;; test that we prevent running simultaneous syncs on the same database
...
...
@@ -186,42 +187,43 @@
{
:analyze-table
(
constantly
nil
)
:describe-database
(
fn
[
_
_
]
(
swap!
sync-count
inc
)
(
Thread/sleep
5
00
)
{
:tables
[]
})
(
Thread/sleep
10
00
)
{
:tables
#
{}
})
:describe-table
(
constantly
nil
)
:details-fields
(
constantly
[])}))
(
driver/register-driver!
:concurrent-sync-test
(
ConcurrentSyncTestDriver.
))
;; only one sync should be going on at a time
(
expect
[
0
1
]
(
tu/with-temp*
[
Database
[
fake-
db
{
:engine
:concurrent-sync-test
}]]
1
(
tu/with-temp*
[
Database
[
db
{
:engine
:concurrent-sync-test
}]]
(
reset!
sync-count
0
)
(
let
[
future-sleep-then-run
(
fn
[
f
]
(
Thread/sleep
100
)
(
future
(
f
)))
concurrent-sync
#
(
sync-database!
fake-db
)]
[
@
sync-count
(
do
(
future-sleep-then-run
concurrent-sync
)
(
future-sleep-then-run
concurrent-sync
)
(
concurrent-sync
)
@
sync-count
)
]))
)
;; ## Test that we will remove field-values when they aren't appropriate
;; start a sync processes in the background. It should take 1000 ms to finish
(
future
(
sync-database!
db
)
)
;; wait 200 ms to make sure everything is going
(
Thread/sleep
200
)
;; Start another in the background. Nothing should happen here because the first is already running
(
future
(
sync-database!
db
))
;; Start another in the foreground. Again, nothing should happen here because the original should still be running
(
sync-database!
db
)
;; Check the number of syncs that took place. Should be 1 (just the first
)
@
sync-count
))
;;; Test that we will remove field-values when they aren't appropriate
(
expect
[[
1
2
3
]
[
1
2
3
]]
(
tu/with-temp*
[
Database
[
fake-
db
{
:engine
:sync-test
}]
RawTable
[
fake-
table
{
:database_id
(
:id
fake-
db
)
,
:name
"movie"
,
:schema
"default"
}]]
(
sync-database!
fake-
db
)
(
let
[
table-id
(
db/select-one-id
Table,
:raw_table_id
(
:id
fake-
table
))
(
tu/with-temp*
[
Database
[
db
{
:engine
:sync-test
}]
RawTable
[
table
{
:database_id
(
u/get-id
db
)
,
:name
"movie"
,
:schema
"default"
}]]
(
sync-database!
db
)
(
let
[
table-id
(
db/select-one-id
Table,
:raw_table_id
(
:id
table
))
field-id
(
db/select-one-id
Field,
:table_id
table-id,
:name
"title"
)]
(
tu/with-temp
FieldValues
[
_
{
:field_id
field-id
:values
"[1,2,3]"
}]
(
let
[
initial-field-values
(
db/select-one-field
:values
FieldValues,
:field_id
field-id
)]
(
sync-database!
fake-
db
)
(
sync-database!
db
)
[
initial-field-values
(
db/select-one-field
:values
FieldValues,
:field_id
field-id
)])))))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment