Skip to content

Commit

Permalink
fix deleteSubscriptionHandler (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
YangKian authored Aug 12, 2021
1 parent 520ce8b commit ad53a0e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions hstream/src/HStream/Server/Handler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,10 @@ deleteSubscriptionHandler ServerContext{..} (ServerNormalRequest _metadata req@D
Log.debug $ "Receive deleteSubscription request: " <> Log.buildString (show req)
(reader, Subscription{..}) <- lookupSubscribedReaders subscribedReaders deleteSubscriptionRequestSubscriptionId
let streamName = transToStreamName $ TL.toStrict subscriptionStreamName
logId <- S.getUnderlyingLogId scLDClient streamName
isExist <- S.doesStreamExists scLDClient streamName
when isExist $ ckpReaderStopReading reader logId
when isExist $ do
logId <- S.getUnderlyingLogId scLDClient streamName
ckpReaderStopReading reader logId
atomically $ do
deleteSubscribedReaders subscribedReaders subscriptionSubscriptionId
modifyTVar' subscribeHeap $ Map.delete subscriptionSubscriptionId
Expand Down
6 changes: 3 additions & 3 deletions hstream/src/HStream/Server/Handler/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ dropHelper sc@ServerContext{..} name checkIfExist isView = do
>> terminateRelatedQueries sc (textToCBytes name)
>> HS.removeStream scLDClient sName
>> returnResp Empty
else if checkIfExist
then returnResp Empty
else returnErrResp StatusInternal "Object does not exist"
else if checkIfExist
then returnResp Empty
else returnErrResp StatusInternal "Object does not exist"

--------------------------------------------------------------------------------
-- Query
Expand Down
9 changes: 9 additions & 0 deletions hstream/test/HStream/HandlerSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ subscribeSpec = describe "HStream.BasicHandlerSpec.Subscribe" $ do
res <- fromJust <$> listSubscriptionRequest client
V.find (\Subscription{..} -> subscriptionSubscriptionId == randomSubsciptionId) res `shouldBe` Nothing

after (cleanSubscriptionEnv randomSubsciptionId randomStreamName) $ it "delete a subscription with underlying stream deleted should success" $ \client -> do
void $ createStreamRequest client $ Stream randomStreamName 1
void $ createSubscriptionRequest client randomSubsciptionId randomStreamName offset
subscribeRequest client randomSubsciptionId `shouldReturn` True
deleteStreamRequest client randomStreamName `shouldReturn` True
deleteSubscriptionRequest client randomSubsciptionId `shouldReturn` True
res <- fromJust <$> listSubscriptionRequest client
V.find (\Subscription{..} -> subscriptionSubscriptionId == randomSubsciptionId) res `shouldBe` Nothing

after (cleanStream randomStreamName) $ it "test hasSubscription request" $ \client -> do
void $ createStreamRequest client $ Stream randomStreamName 1
-- check a nonexistent subscriptionId should return False
Expand Down

0 comments on commit ad53a0e

Please sign in to comment.