10000 Testing multiple batches in single connection · postgres-haskell/postgres-wire@8cd8a1a · GitHub
[go: up one dir, main page]

Skip to content

Commit 8cd8a1a

Browse files
Testing multiple batches in single connection
1 parent 89c8720 commit 8cd8a1a

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tests/Driver.hs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ testDriver :: TestTree
2020
testDriver = testGroup "Driver"
2121
[ testCase "Single batch" testBatch
2222
, testCase "Two batches" testTwoBatches
23+
, testCase "Multiple batches" testMultipleBatches
2324
, testCase "Empty query" testEmptyQuery
2425
, testCase "Query without result" testQueryWithoutResult
2526
, testCase "Invalid queries" testInvalidBatch
2627
, testCase "Describe statement" testDescribeStatement
2728
, testCase "Describe statement with no data" testDescribeStatementNoData
2829
, testCase "Describe empty statement" testDescribeStatementEmpty
30+
, testCase "SimpleQuery" testSimpleQuery
2931
]
3032

3133
makeQuery1 :: B.ByteString -> Query
@@ -38,6 +40,9 @@ fromRight :: Either e a -> a
3840
fromRight (Right v) = v
3941
fromRight _ = error "fromRight"
4042

43+
fromMessage :: DataMessage -> B.ByteString
44+
fromMessage (DataMessage [[v]]) = v
45+
fromMessage _ = error "from message"
4146

4247
testBatch :: IO ()
4348
testBatch = withConnection $ \c -> do
@@ -65,9 +70,19 @@ testTwoBatches = withConnection $ \c -> do
6570
readReadyForQuery c
6671

6772
DataMessage [[BS.pack (show $ a + b)]] @=? fromRight r
73+
74+
testMultipleBatches :: IO ()
75+
testMultipleBatches = withConnection $ replicateM_ 10 . assertSingleBatch
6876
where
69-
fromMessage (DataMessage [[v]]) = v
70-
fromMessage _ = error "from message"
77+
assertSingleBatch c = do
78+
let a = "5"
79+
b = "6"
80+
sendBatchAndSync c [ makeQuery1 a, makeQuery1 b]
81+
r1 <- readNextData c
82+
r2 <- readNextData c
83+
readReadyForQuery c
84+
DataMessage [[a]] @=? fromRight r1
85+
DataMessage [[b]] @=? fromRight r2
7186

7287
testEmptyQuery :: IO ()
7388
testEmptyQuery = assertQueryNoData $
@@ -142,3 +157,13 @@ testDescribeStatementEmpty = withConnection $ \c -> do
142157
assertBool "Should be empty" $ V.null (fst r)
143158
assertBool "Should be empty" $ V.null (snd r)
144159

160+
testSimpleQuery :: IO ()
161+
testSimpleQuery = withConnection $ \c -> do
162+
r <- sendSimpleQuery c $
163+
"DROP TABLE IF EXISTS a;"
164+
<> "CREATE TABLE a(v int);"
165+
<> "INSERT INTO a VALUES (1), (2), (3);"
166+
<> "SELECT * FROM a;"
167+
<> "DROP TABLE a;"
168+
assertBool "Should be Right" $ isRight r
169+

0 commit comments

Comments
 (0)
0