@@ -20,12 +20,14 @@ testDriver :: TestTree
20
20
testDriver = testGroup " Driver"
21
21
[ testCase " Single batch" testBatch
22
22
, testCase " Two batches" testTwoBatches
23
+ , testCase " Multiple batches" testMultipleBatches
23
24
, testCase " Empty query" testEmptyQuery
24
25
, testCase " Query without result" testQueryWithoutResult
25
26
, testCase " Invalid queries" testInvalidBatch
26
27
, testCase " Describe statement" testDescribeStatement
27
28
, testCase " Describe statement with no data" testDescribeStatementNoData
28
29
, testCase " Describe empty statement" testDescribeStatementEmpty
30
+ , testCase " SimpleQuery" testSimpleQuery
29
31
]
30
32
31
33
makeQuery1 :: B. ByteString -> Query
@@ -38,6 +40,9 @@ fromRight :: Either e a -> a
38
40
fromRight (Right v) = v
39
41
fromRight _ = error " fromRight"
40
42
43
+ fromMessage :: DataMessage -> B. ByteString
44
+ fromMessage (DataMessage [[v]]) = v
45
+ fromMessage _ = error " from message"
41
46
42
47
testBatch :: IO ()
43
48
testBatch = withConnection $ \ c -> do
@@ -65,9 +70,19 @@ testTwoBatches = withConnection $ \c -> do
65
70
readReadyForQuery c
66
71
67
72
DataMessage [[BS. pack (show $ a + b)]] @=? fromRight r
73
+
74
+ testMultipleBatches :: IO ()
75
+ testMultipleBatches = withConnection $ replicateM_ 10 . assertSingleBatch
68
76
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
71
86
72
87
testEmptyQuery :: IO ()
73
88
testEmptyQuery = assertQueryNoData $
@@ -142,3 +157,13 @@ testDescribeStatementEmpty = withConnection $ \c -> do
142
157
assertBool " Should be empty" $ V. null (fst r)
143
158
assertBool " Should be empty" $ V. null (snd r)
144
159
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