Haxl/tests/AdoTests.hs
Simon Marlow b67f7f6370 Haxl 2
Summary:
This is a complete reworking of the way that Haxl schedules I/O.  The
main benefits are:

* Data fetches are no longer organised into rounds, but can be
  arbitrarily overlapped with each other and with computation.  The
  scheduler supports an arbitrary queue of work items which it can
  evaluate while data-fetching is taking place in the background.  To
  take advantage of this, data sources must implement a new form of
  `PerformFetch`, namely `BackgroundFetch`.  The old forms of
  `PerformFetch` are still supported, but won't benefit from any
  additional concurrency.

* It is now possible to specify on a per-data-source basis whether
  fetching should be optimised for batching or for latency.  A request
  to a data source that doesn't benefit from batching can be submitted
  immediately.  This is done with the new `schedulerHint` method of
  `DataSource`.

Reviewed By: niteria

Differential Revision: D4938005

fbshipit-source-id: 96f12ad05ee62d62474ee4cc1215f19d0a6fcdf3
2017-10-03 00:28:54 -07:00

50 lines
987 B
Haskell

{-# LANGUAGE RebindableSyntax, OverloadedStrings, ApplicativeDo #-}
module AdoTests (tests) where
import TestUtils
import MockTAO
import Control.Applicative
import Test.HUnit
import Prelude()
import Haxl.Prelude
-- -----------------------------------------------------------------------------
--
-- Test ApplicativeDo batching
--
ado1 = expectRounds 1 12 ado1_
ado1_ = do
a <- friendsOf =<< id1
b <- friendsOf =<< id2
return (length (a ++ b))
ado2 = expectRounds 1 12 ado2_
ado2_ = do
x <- id1
a <- friendsOf x
y <- id2
b <- friendsOf y
return (length (a ++ b))
ado3 = expectRounds 2 11 ado3_
ado3_ = do
x <- id1
a <- friendsOf x
a' <- friendsOf =<< if null a then id3 else id4
y <- id2
b <- friendsOf y
b' <- friendsOf =<< if null b then id4 else id3
return (length (a' ++ b'))
tests future = TestList
[ TestLabel "ado1" $ TestCase (ado1 future)
, TestLabel "ado2" $ TestCase (ado2 future)
, TestLabel "ado3" $ TestCase (ado3 future)
]