Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make query arguments in tests pairwise distinct to prevent BN query caching #212

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/IC/Test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,10 +2574,17 @@ icTests my_sub other_sub =
, "sender" =: GBlob defaultUser
, "canister_id" =: GBlob cid
, "method_name" =: GText "query"
, "arg" =: GBlob (run reply)
, "arg" =: GBlob (run ((debugPrint $ i2b $ int 0) >>> reply))
]
bad_req <- addNonce >=> addExpiry $ rec
[ "request_type" =: GText "query"
, "sender" =: GBlob defaultUser
, "canister_id" =: GBlob cid
, "method_name" =: GText "query"
, "arg" =: GBlob (run ((debugPrint $ i2b $ int 1) >>> reply))
]
queryCBOR cid good_req >>= queryResponse >>= isReply >>= is ""
env (mod_req good_req) >>= postQueryCBOR cid >>= code4xx
env (mod_req bad_req) >>= postQueryCBOR cid >>= code4xx

, simpleTestCase "in empty read state request" ecid $ \cid -> do
good_req <- addNonce >=> addExpiry $ readStateEmpty
Expand Down
18 changes: 14 additions & 4 deletions src/IC/Test/Spec/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import qualified Data.Set as S
import qualified Data.Vector as Vec
import qualified Data.Word as W
import Numeric.Natural
import Data.IORef
import Data.List
import Test.Tasty
import Test.Tasty.HUnit
Expand All @@ -30,8 +31,7 @@ import Network.HTTP.Client
import qualified Data.Binary.Get as Get
import Codec.Candid (Principal(..))
import qualified Codec.Candid as Candid
import Control.Concurrent
import System.Timeout
import System.IO.Unsafe (unsafePerformIO)

import IC.HTTP.GenR
import IC.HTTP.RequestId
Expand Down Expand Up @@ -289,14 +289,24 @@ callTwice' :: (HasCallStack, HasAgentConfig) => Blob -> Prog -> IO ReqResponse
callTwice' cid prog = awaitCallTwice cid (callRequest cid prog)


counterRef :: IORef Word32
counterRef =
unsafePerformIO (newIORef 0)
{-# NOINLINE counterRef #-}

incrementCount :: IO Word32
incrementCount =
atomicModifyIORef' counterRef (\count -> (count + 1, count + 1))

query' :: (HasCallStack, HasAgentConfig) => Blob -> Prog -> IO ReqResponse
query' cid prog =
query' cid prog = do
ctr <- incrementCount
queryCBOR cid >=> queryResponse $ rec
[ "request_type" =: GText "query"
, "sender" =: GBlob defaultUser
, "canister_id" =: GBlob cid
, "method_name" =: GText "query"
, "arg" =: GBlob (run prog)
, "arg" =: GBlob (run ((debugPrint $ i2b $ int ctr) >>> prog))
]

query :: (HasCallStack, HasAgentConfig) => Blob -> Prog -> IO Blob
Expand Down