Skip to content

Commit babdfe7

Browse files
committed
Use single command to insert many items together in test
1 parent 743645a commit babdfe7

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

tests/Test/Connector/PostgreSQL.hs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,22 @@ testPostgreSQL p = do
7575
it "splitBoundaries does not produce overlapping sections" $ do
7676
with (PartitionCount 1) $ \conn table topic connected -> do
7777
let odds = [1, 3..]
78-
evens = [2,4..]
78+
evens = [2, 4..]
7979
n = 2000
8080
-- cheat a little bit by specifying the ids.
81-
insertV :: Int -> IO ()
82-
insertV x = void $ P.execute_ conn $ fromString $
83-
"INSERT INTO " <> tableName table
84-
<> " (id, aggregate_id, sequence_number) VALUES ("
85-
<> show x <> ","<> show x <> ", "<> show x <>
86-
")"
81+
insertMany :: [Int] -> IO ()
82+
insertMany xs = void $ P.executeMany conn q [(x,x,x) | x <- xs]
83+
where
84+
q = fromString $ "INSERT INTO " <> tableName table <>
85+
" (id, aggregate_id, sequence_number) VALUES (?, ?, ?)"
8786

8887
-- leave lots of gaps
89-
forM_ (take n odds) insertV
88+
insertMany $ take n odds
9089
connected $ Topic.withConsumer topic group $ \consumer -> deadline (seconds 1) $ do
9190
oddEntries <- forM [1..n] $ \_ -> readEntry @Event consumer
9291

9392
-- fill all the gaps
94-
forM_ (take n evens) insertV
93+
insertMany (take n evens)
9594
evenEntries <- forM [1..n] $ \_ -> readEntry @Event consumer
9695

9796
let ids = fmap (e_id . fst) $ oddEntries <> evenEntries

0 commit comments

Comments
 (0)