-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMain.hs
749 lines (659 loc) · 37 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
{-# OPTIONS_GHC -Wno-orphans #-}
module Main (main) where
import Control.Concurrent.Lifted
import Control.Monad
import Control.Monad.Base
import Control.Monad.Catch
import Control.Monad.State qualified as S
import Control.Monad.Trans.Control
import Data.Aeson hiding ((<?>))
import Data.ByteString qualified as BS
import Data.Char
import Data.Function
import Data.Int
import Data.Maybe
import Data.Text qualified as T
import Data.Time
import Data.Typeable
import Data.UUID.Types qualified as U
import Data.Word
import System.Environment
import System.Exit
import System.Random
import System.Timeout.Lifted
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test, assertEqual)
import Test.QuickCheck
import Test.QuickCheck.Gen
import Test.QuickCheck.Random
import TextShow
import Data.Monoid.Utils
import Database.PostgreSQL.PQTypes
import Prelude.Instances ()
import Test.Aeson.Compat (Value0)
import Test.QuickCheck.Arbitrary.Instances
type InnerTestEnv = S.StateT QCGen (DBT IO)
newtype TestEnv a = TestEnv {unTestEnv :: InnerTestEnv a}
deriving
( Applicative
, Functor
, Monad
, MonadFail
, MonadBase IO
, MonadCatch
, MonadDB
, MonadMask
, MonadThrow
)
instance MonadBaseControl IO TestEnv where
type StM TestEnv a = StM InnerTestEnv a
liftBaseWith f = TestEnv $ liftBaseWith (\run -> f $ run . unTestEnv)
restoreM = TestEnv . restoreM
withQCGen :: (QCGen -> r) -> TestEnv r
withQCGen f = do
gen <- TestEnv $ S.state split
pure (f gen)
----------------------------------------
type TestData = (QCGen, ConnectionSettings)
runTestEnv :: TestData -> TransactionSettings -> TestEnv a -> IO a
runTestEnv (env, connSettings) ts m = runDBT cs ts $ S.evalStateT (unTestEnv m) env
where
ConnectionSource cs = simpleSource connSettings
runTimes :: Monad m => Int -> m () -> m ()
runTimes !n m = case n of
0 -> pure ()
_ -> m >> runTimes (n - 1) m
----------------------------------------
newtype AsciiChar = AsciiChar {unAsciiChar :: Char}
deriving (Eq, Show)
instance PQFormat AsciiChar where
pqFormat = pqFormat @Char
instance ToSQL AsciiChar where
type PQDest AsciiChar = PQDest Char
toSQL = toSQL . unAsciiChar
instance FromSQL AsciiChar where
type PQBase AsciiChar = PQBase Char
fromSQL = fmap AsciiChar . fromSQL
instance Arbitrary AsciiChar where
-- QuickCheck >= 2.10 changed Arbitrary Char instance to include proper
-- Unicode CharS, but PostgreSQL only accepts ASCII ones.
arbitrary = AsciiChar . chr <$> oneof [choose (0, 127), choose (0, 255)]
shrink = map AsciiChar . shrink . unAsciiChar
instance Arbitrary Interval where
arbitrary =
Interval
<$> abs `fmap` arbitrary
<*> choose (0, 11)
<*> choose (0, 364)
<*> choose (0, 23)
<*> choose (0, 59)
<*> choose (0, 59)
<*> choose (0, 999999)
instance (Arbitrary a1, Arbitrary a2) => Arbitrary (a1 :*: a2) where
arbitrary = (:*:) <$> arbitrary <*> arbitrary
instance Arbitrary a => Arbitrary (Composite a) where
arbitrary = Composite <$> arbitrary
instance Arbitrary json => Arbitrary (JSON json) where
arbitrary = JSON <$> arbitrary
instance Arbitrary jsonb => Arbitrary (JSONB jsonb) where
arbitrary = JSONB <$> arbitrary
instance Arbitrary a => Arbitrary (Array1 a) where
arbitrary = arbitraryArray1 Array1
instance Arbitrary a => Arbitrary (CompositeArray1 a) where
arbitrary = arbitraryArray1 CompositeArray1
instance Arbitrary a => Arbitrary (Array2 a) where
arbitrary = arbitraryArray2 Array2
instance Arbitrary a => Arbitrary (CompositeArray2 a) where
arbitrary = arbitraryArray2 CompositeArray2
arbitraryArray1 :: Arbitrary a => (a -> b) -> Gen b
arbitraryArray1 arr1 = arr1 <$> arbitrary
arbitraryArray2 :: Arbitrary a => ([[a]] -> b) -> Gen b
arbitraryArray2 arr2 = do
let bound = (`mod` 100) . abs
outerDim <- bound <$> arbitrary
innerDim <- bound <$> arbitrary
arr2 <$> vectorOf outerDim (vectorOf innerDim arbitrary)
----------------------------------------
data Simple = Simple (Maybe Int32) (Maybe Day)
deriving (Eq, Ord, Show)
type instance CompositeRow Simple = (Maybe Int32, Maybe Day)
instance PQFormat Simple where
pqFormat = "%simple_"
instance CompositeFromSQL Simple where
toComposite (a, b) = Simple a b
instance CompositeToSQL Simple where
fromComposite (Simple a b) = (a, b)
instance Arbitrary Simple where
arbitrary = Simple <$> arbitrary <*> arbitrary
data Nested = Nested (Maybe Double) (Maybe Simple)
deriving (Eq, Ord, Show)
type instance CompositeRow Nested = (Maybe Double, Maybe (Composite Simple))
instance PQFormat Nested where
pqFormat = "%nested_"
instance CompositeFromSQL Nested where
toComposite (a, b) = Nested a (unComposite <$> b)
instance CompositeToSQL Nested where
fromComposite (Nested a b) = (a, Composite <$> b)
instance Arbitrary Nested where
arbitrary = Nested <$> arbitrary <*> arbitrary
----------------------------------------
epsilon :: Fractional a => a
epsilon = 0.00001
eqTOD :: TimeOfDay -> TimeOfDay -> Bool
eqTOD a b =
(todHour a == todHour b)
&& (todMin a == todMin b)
&& (abs (todSec a - todSec b) < epsilon)
eqLT :: LocalTime -> LocalTime -> Bool
eqLT a b =
(localDay a == localDay b)
&& (localTimeOfDay a `eqTOD` localTimeOfDay b)
eqUTCT :: UTCTime -> UTCTime -> Bool
eqUTCT a b =
(utctDay a == utctDay b)
&& (abs (utctDayTime a - utctDayTime b) < epsilon)
eqArray2 :: Eq a => Array2 a -> Array2 a -> Bool
eqArray2 (Array2 []) (Array2 arr) = all null arr
eqArray2 (Array2 arr) (Array2 []) = all null arr
eqArray2 a b = a == b
eqCompositeArray2 :: Eq a => CompositeArray2 a -> CompositeArray2 a -> Bool
eqCompositeArray2 (CompositeArray2 []) (CompositeArray2 arr) = all null arr
eqCompositeArray2 (CompositeArray2 arr) (CompositeArray2 []) = all null arr
eqCompositeArray2 a b = a == b
----------------------------------------
tsNoTrans :: TransactionSettings
tsNoTrans = defaultTransactionSettings {tsAutoTransaction = False}
randomValue :: Arbitrary t => Int -> TestEnv t
randomValue n = withQCGen $ \gen -> unGen arbitrary gen n
assertEqual
:: (Show a, MonadBase IO m)
=> String
-> a
-> a
-> (a -> a -> Bool)
-> m ()
assertEqual preface expected actual eq =
liftBase $ unless (actual `eq` expected) (assertFailure msg)
where
msg =
(if null preface then "" else preface ++ "\n") ++ ("expected: " ++ show expected ++ "\n but got: " ++ show actual)
assertEqualEq :: (Eq a, Show a, MonadBase IO m) => String -> a -> a -> m ()
assertEqualEq preface expected actual = assertEqual preface expected actual (==)
----------------------------------------
sqlGenInts :: Int32 -> SQL
sqlGenInts n =
smconcat
[ "WITH RECURSIVE ints(n) AS"
, "( VALUES (1) UNION ALL SELECT n+1 FROM ints WHERE n <" <?> n
, ") SELECT n FROM ints"
]
cursorTest :: TestData -> Test
cursorTest td =
testGroup
"Cursors"
[ basicCursorWorks
, scrollableCursorWorks
, withHoldCursorWorks
, doubleCloseWorks
]
where
basicCursorWorks = testCase "Basic cursor works" $ do
runTestEnv td defaultTransactionSettings $ do
withCursor "ints" NoScroll NoHold (sqlGenInts 5) $ \cursor -> do
xs <- (`fix` []) $ \loop acc ->
cursorFetch cursor CD_Next >>= \case
0 -> pure $ reverse acc
1 -> do
(n :: Int32) <- fetchOne runIdentity
loop $ n : acc
n -> error $ "Unexpected number of rows: " ++ show n
assertEqualEq "Data fetched correctly" [1 .. 5] xs
scrollableCursorWorks = testCase "Cursor declared as SCROLL works" $ do
runTestEnv td defaultTransactionSettings $ do
withCursor "ints" Scroll NoHold (sqlGenInts 10) $ \cursor -> do
checkMove cursor CD_Next 1
checkMove cursor CD_Prior 0
checkMove cursor CD_First 1
checkMove cursor CD_Last 1
checkMove cursor CD_Backward_All 9
checkMove cursor CD_Forward_All 10
checkMove cursor (CD_Absolute 0) 0
checkMove cursor (CD_Relative 0) 0
checkMove cursor (CD_Forward 5) 5
checkMove cursor (CD_Backward 5) 4
cursorFetch_ cursor CD_Forward_All
xs1 :: [Int32] <- fetchMany runIdentity
assertEqualEq "xs1 is correct" [1 .. 10] xs1
cursorFetch_ cursor CD_Backward_All
xs2 :: [Int32] <- fetchMany runIdentity
assertEqualEq "xs2 is correct" (reverse [1 .. 10]) xs2
where
checkMove cursor cd expected = do
moved <- cursorMove cursor cd
assertEqualEq
( "Moving cursor with"
<+> show cd
<+> "would fetch a correct amount of rows"
)
expected
moved
withHoldCursorWorks = testCase "Cursor declared as WITH HOLD works" $ do
runTestEnv td tsNoTrans $ do
withCursor "ints" NoScroll Hold (sqlGenInts 10) $ \cursor -> do
cursorFetch_ cursor CD_Forward_All
sum_ :: Int32 <- sum . fmap runIdentity <$> queryResult
assertEqualEq "sum_ is correct" 55 sum_
doubleCloseWorks = testCase "Double CLOSE works on a cursor" $ do
runTestEnv td defaultTransactionSettings $ do
withCursorSQL "ints" NoScroll NoHold "SELECT 1" $ \_cursor -> do
-- Commiting a transaction closes the cursor
commit
queryInterruptionTest :: TestData -> Test
queryInterruptionTest td = testCase "Queries are interruptible" $ do
let sleep = "SELECT pg_sleep(2)"
ints = sqlGenInts 5000000
runTestEnv td tsNoTrans $ do
testQuery id sleep
testQuery id ints
runTestEnv td defaultTransactionSettings $ do
testQuery (withSavepoint "ints") ints
testQuery (withSavepoint "sleep") sleep
where
testQuery m sql =
timeout 500000 (m $ runSQL_ sql) >>= \case
Just _ -> liftBase $ do
assertFailure $ "Query" <+> show sql <+> "wasn't interrupted in time"
Nothing -> pure ()
autocommitTest :: TestData -> Test
autocommitTest td = testCase "Autocommit mode works"
. runTestEnv td tsNoTrans
$ do
let sint = Identity (1 :: Int32)
runQuery_ $ rawSQL "INSERT INTO test1_ (a) VALUES ($1)" sint
withNewConnection $ do
n <- runQuery $ rawSQL "SELECT a FROM test1_ WHERE a = $1" sint
assertEqualEq "Other connection sees autocommited data" 1 n
runQuery_ $ rawSQL "DELETE FROM test1_ WHERE a = $1" sint
setRoleTest :: TestData -> Test
setRoleTest td = testCase "SET ROLE works" . bracket createRole dropRole $ \case
False -> putStrLn "Cannot create role, skipping SET ROLE test"
True -> do
runDBT roledCs defaultTransactionSettings $ do
runSQL_ "SELECT CURRENT_USER::text"
role <- fetchOne (runIdentity @String)
assertEqualEq "Role set successfully" testRole role
where
testRole :: String
testRole = "hpqtypes_test_role"
ConnectionSource roledCs =
simpleSource $
(snd td)
{ csRole = Just $ unsafeSQL testRole
}
createRole = runTestEnv td defaultTransactionSettings $ do
try (runSQL_ $ "CREATE ROLE" <+> unsafeSQL testRole) >>= \case
Right () -> pure True
Left DBException {} -> pure False
dropRole = \case
False -> pure ()
True -> runTestEnv td defaultTransactionSettings $ do
runSQL_ $ "DROP ROLE" <+> unsafeSQL testRole
preparedStatementTest :: TestData -> Test
preparedStatementTest td = testCase "Execution of prepared statements works"
. runTestEnv td defaultTransactionSettings
$ do
let name = "select1"
checkPrepared name "Statement is not prepared" 0
execPrepared name 42
checkPrepared name "Statement is prepared" 1
execPrepared name 89
let i3 = "lalala" :: String
-- Changing parameter type in an already prepared statement shouldn't work.
o3 <- try . runPreparedQuery_ name $ ("SELECT" <?> i3)
case o3 of
Left DBException {} -> pure ()
Right r3 -> liftBase . assertFailure $ "Expected DBException, but got" <+> show r3
where
checkPrepared :: QueryName -> String -> Int -> TestEnv ()
checkPrepared (QueryName name) assertTitle expected = do
n <- runSQL $ "SELECT TRUE FROM pg_prepared_statements WHERE name =" <?> name
assertEqualEq assertTitle expected n
execPrepared :: QueryName -> Int32 -> TestEnv ()
execPrepared name input = do
runPreparedQuery_ name $ "SELECT" <?> input
output <- fetchOne runIdentity
assertEqualEq "Results match" input output
readOnlyTest :: TestData -> Test
readOnlyTest td = testCase "Read only transaction mode works"
. runTestEnv
td
defaultTransactionSettings {tsPermissions = ReadOnly}
$ do
let sint = Identity (2 :: Int32)
eres <- try . runQuery_ $ rawSQL "INSERT INTO test1_ (a) VALUES ($1)" sint
case eres :: Either DBException () of
Left _ -> pure ()
Right _ -> liftBase . assertFailure $ "DBException wasn't thrown"
rollback
n <- runQuery $ rawSQL "SELECT a FROM test1_ WHERE a = $1" sint
assertEqualEq "SELECT works in read only mode" 0 n
savepointTest :: TestData -> Test
savepointTest td = testCase "Savepoint support works"
. runTestEnv td defaultTransactionSettings
$ do
let int1 = 3 :: Int32
int2 = 4 :: Int32
-- action executed within withSavepoint throws
runQuery_ $ rawSQL "INSERT INTO test1_ (a) VALUES ($1)" (Identity int1)
_ :: Either DBException () <- try . withSavepoint (Savepoint "test") $ do
runQuery_ $ rawSQL "INSERT INTO test1_ (a) VALUES ($1)" (Identity int2)
runSQL_ "SELECT * FROM table_that_is_not_there"
runQuery_ $ rawSQL "SELECT a FROM test1_ WHERE a IN ($1, $2)" (int1, int2)
res1 <- fetchMany runIdentity
assertEqualEq "Part of transaction was rolled back" [int1] res1
rollback
-- action executed within withSavepoint doesn't throw
runQuery_ $ rawSQL "INSERT INTO test1_ (a) VALUES ($1)" (Identity int1)
withSavepoint (Savepoint "test") $ do
runQuery_ $ rawSQL "INSERT INTO test1_ (a) VALUES ($1)" (Identity int2)
runQuery_ $
rawSQL
"SELECT a FROM test1_ WHERE a IN ($1, $2) ORDER BY a"
(int1, int2)
res2 <- fetchMany runIdentity
assertEqualEq "Result of all queries is visible" [int1, int2] res2
notifyTest :: TestData -> Test
notifyTest td = testCase "Notifications work" . runTestEnv td tsNoTrans $ do
listen chan
forkNewConn $ notify chan payload
mnt1 <- getNotification 250000
liftBase $ assertBool "Notification received" (isJust mnt1)
Just nt1 <- pure mnt1
assertEqualEq "Channels are equal" chan (ntChannel nt1)
assertEqualEq "Payloads are equal" payload (ntPayload nt1)
unlisten chan
forkNewConn $ notify chan payload
mnt2 <- getNotification 250000
assertEqualEq "No notification received after unlisten" Nothing mnt2
listen chan
unlistenAll
forkNewConn $ notify chan payload
mnt3 <- getNotification 250000
assertEqualEq "No notification received after unlistenAll" Nothing mnt3
where
chan = "test_channel"
payload = "test_payload"
forkNewConn = void . fork . withNewConnection
transactionTest :: TestData -> IsolationLevel -> Test
transactionTest td lvl =
testCase
( "Auto transaction works by default with isolation level"
<+> show lvl
)
. runTestEnv
td
defaultTransactionSettings {tsIsolationLevel = lvl}
$ do
let sint = Identity (5 :: Int32)
runQuery_ $ rawSQL "INSERT INTO test1_ (a) VALUES ($1)" sint
withNewConnection $ do
n <- runQuery $ rawSQL "SELECT a FROM test1_ WHERE a = $1" sint
assertEqualEq "Other connection doesn't see uncommited data" 0 n
rollback
nullTest
:: forall t
. (Show t, ToSQL t, FromSQL t, Typeable t)
=> TestData
-> t
-> Test
nullTest td t = testCase
( "Attempt to get non-NULL value of type"
<+> show (typeOf t)
<+> "fails if NULL is provided"
)
. runTestEnv td defaultTransactionSettings
$ do
runSQL_ $ "SELECT" <?> (Nothing :: Maybe t)
eres <- try $ fetchOne runIdentity
case eres :: Either DBException t of
Left _ -> pure ()
Right _ -> liftBase . assertFailure $ "DBException wasn't thrown"
putGetTest
:: forall t
. (Arbitrary t, Show t, ToSQL t, FromSQL t, Typeable t)
=> TestData
-> Int
-> t
-> (t -> t -> Bool)
-> Test
putGetTest td n t eq = testCase
( "Putting value of type"
<+> show (typeOf t)
<+> "through database doesn't change its value"
)
. runTestEnv td defaultTransactionSettings
. runTimes 1000
$ do
v :: t <- randomValue n
-- liftBase . putStrLn . show $ v
runSQL_ $ "SELECT" <?> v
v' <- fetchOne runIdentity
assertEqual "Value doesn't change after getting through database" v v' eq
uuidTest :: TestData -> Test
uuidTest td = testCase "UUID encoding / decoding test" $ do
let uuidStr = "550e8400-e29b-41d4-a716-446655440000"
Just uuid <- pure $ U.fromText uuidStr
runTestEnv td defaultTransactionSettings $ do
runSQL_ . mkSQL $ ("SELECT '" `mappend` uuidStr `mappend` "' :: uuid")
uuid2 <- fetchOne runIdentity
assertEqual "UUID is decoded correctly" uuid uuid2 (==)
runQuery_ $ rawSQL " SELECT $1 :: text" (Identity uuid)
uuidStr2 <- fetchOne runIdentity
assertEqual "UUID is encoded correctly" uuidStr uuidStr2 (==)
xmlTest :: TestData -> Test
xmlTest td = testCase "Put and get XML value works"
. runTestEnv td defaultTransactionSettings
$ do
runSQL_ "SET CLIENT_ENCODING TO 'UTF8'"
let v = XML "some<tag>stringå</tag>"
runSQL_ "SELECT XML 'some<tag>stringå</tag>'"
v' <- fetchOne runIdentity
assertEqualEq "XML value correct" v v'
runSQL_ $ "SELECT" <?> v
v'' <- fetchOne runIdentity
assertEqualEq "XML value correct" v v''
runSQL_ "SET CLIENT_ENCODING TO 'latin-1'"
rowTest
:: forall row
. (Arbitrary row, Eq row, Show row, ToRow row, FromRow row)
=> TestData
-> row
-> Test
rowTest td _r = testCase
( "Putting row of length"
<+> show (pqVariables @row)
<+> "through database works"
)
. runTestEnv td defaultTransactionSettings
. runTimes 100
$ do
row :: row <- randomValue 100
let fmt = mintercalate ", " $ map (T.append "$" . showt) [1 .. pqVariables @row]
runQuery_ $ rawSQL ("SELECT" <+> fmt) row
row' <- fetchOne id
assertEqualEq "Row doesn't change after getting through database" row row'
_printTime :: MonadBase IO m => m a -> m a
_printTime m = do
t <- liftBase getCurrentTime
res <- m
t' <- liftBase getCurrentTime
liftBase . putStrLn $ "Time: " ++ show (diffUTCTime t' t)
pure res
tests :: TestData -> [Test]
tests td =
[ autocommitTest td
, setRoleTest td
, preparedStatementTest td
, xmlTest td
, readOnlyTest td
, savepointTest td
, notifyTest td
, queryInterruptionTest td
, cursorTest td
, uuidTest td
, transactionTest td ReadCommitted
, transactionTest td RepeatableRead
, transactionTest td Serializable
, nullTest td (u :: Int16)
, nullTest td (u :: Int32)
, nullTest td (u :: Int64)
, nullTest td (u :: Float)
, nullTest td (u :: Double)
, nullTest td (u :: Bool)
, nullTest td (u :: AsciiChar)
, nullTest td (u :: Word8)
, nullTest td (u :: String)
, nullTest td (u :: BS.ByteString)
, nullTest td (u :: T.Text)
, nullTest td (u :: U.UUID)
, nullTest td (u :: JSON Value)
, nullTest td (u :: JSONB Value)
, nullTest td (u :: XML)
, nullTest td (u :: Interval)
, nullTest td (u :: Day)
, nullTest td (u :: TimeOfDay)
, nullTest td (u :: LocalTime)
, nullTest td (u :: UTCTime)
, nullTest td (u :: Array1 Int32)
, nullTest td (u :: Array2 Double)
, nullTest td (u :: Composite Simple)
, nullTest td (u :: CompositeArray1 Simple)
, nullTest td (u :: CompositeArray2 Simple)
, putGetTest td 100 (u :: Int16) (==)
, putGetTest td 100 (u :: Int32) (==)
, putGetTest td 100 (u :: Int64) (==)
, putGetTest td 10000 (u :: Float) (==)
, putGetTest td 10000 (u :: Double) (==)
, putGetTest td 100 (u :: Bool) (==)
, putGetTest td 100 (u :: AsciiChar) (==)
, putGetTest td 100 (u :: Word8) (==)
, putGetTest td 1000 (u :: String0) (==)
, putGetTest td 1000 (u :: BS.ByteString) (==)
, putGetTest td 1000 (u :: T.Text) (==)
, putGetTest td 1000 (u :: U.UUID) (==)
, putGetTest td 50 (u :: JSON Value0) (==)
, putGetTest td 50 (u :: JSONB Value0) (==)
, putGetTest td 20 (u :: Array1 (JSON Value0)) (==)
, putGetTest td 20 (u :: Array1 (JSONB Value0)) (==)
, putGetTest td 50 (u :: Interval) (==)
, putGetTest td 1000000 (u :: Day) (==)
, putGetTest td 10000 (u :: TimeOfDay) eqTOD
, putGetTest td 500000 (u :: LocalTime) eqLT
, putGetTest td 500000 (u :: UTCTime) eqUTCT
, putGetTest td 1000 (u :: Array1 Int32) (==)
, putGetTest td 1000 (u :: Array2 Double) eqArray2
, putGetTest td 100000 (u :: Composite Simple) (==)
, putGetTest td 1000 (u :: CompositeArray1 Simple) (==)
, putGetTest td 1000 (u :: CompositeArray2 Simple) eqCompositeArray2
, putGetTest td 100000 (u :: Composite Nested) (==)
, putGetTest td 1000 (u :: CompositeArray1 Nested) (==)
, putGetTest td 1000 (u :: CompositeArray2 Nested) eqCompositeArray2
, rowTest td (u :: Identity Int16)
, rowTest td (u :: Identity T.Text :*: (Double, Int16))
, rowTest td (u :: (T.Text, Double) :*: Identity Int16)
, rowTest td (u :: (Int16, T.Text, Int64, Double) :*: Identity Bool :*: (String0, AsciiChar))
, rowTest td (u :: (Int16, Int32))
, rowTest td (u :: (Int16, Int32, Int64))
, rowTest td (u :: (Int16, Int32, Int64, Float))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, U.UUID))
, rowTest td (u :: (Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, Day, Array1 Int32, Composite Simple, CompositeArray1 Simple, Composite Nested, CompositeArray1 Nested, Int16, Int32, Int64, Float, Double, Bool, AsciiChar, Word8, String0, BS.ByteString, T.Text, BS.ByteString, U.UUID, Day))
]
where
u = undefined
----------------------------------------
createStructures :: ConnectionSourceM IO -> IO ()
createStructures cs = runDBT cs defaultTransactionSettings $ do
liftBase . putStrLn $ "Creating structures..."
runSQL_ "CREATE TABLE test1_ (a INTEGER)"
runSQL_ "CREATE TYPE simple_ AS (a INTEGER, b DATE)"
runSQL_ "CREATE TYPE nested_ AS (d DOUBLE PRECISION, s SIMPLE_)"
dropStructures :: ConnectionSourceM IO -> IO ()
dropStructures cs = runDBT cs defaultTransactionSettings $ do
liftBase . putStrLn $ "Dropping structures..."
runSQL_ "DROP TYPE nested_"
runSQL_ "DROP TYPE simple_"
runSQL_ "DROP TABLE test1_"
getConnString :: IO (T.Text, [String])
getConnString =
getArgs >>= \case
connString : args -> pure (T.pack connString, args)
[] ->
lookupEnv "GITHUB_ACTIONS" >>= \case
Just "true" -> pure ("host=postgres user=postgres password=postgres", [])
_ -> printUsage >> exitFailure
where
printUsage = do
prog <- getProgName
putStrLn $
"Usage:"
<+> prog
<+> "<connection info string> [test-framework args]"
main :: IO ()
main = do
(connString, args) <- getConnString
let connSettings =
defaultConnectionSettings
{ csConnInfo = connString
, csClientEncoding = Just "latin1"
}
ConnectionSource connSource = simpleSource connSettings
createStructures connSource
gen <- newQCGen
putStrLn $ "PRNG:" <+> show gen
finally (defaultMainWithArgs (tests (gen, connSettings {csComposites = ["simple_", "nested_"]})) args) $ do
dropStructures connSource