diff --git a/hstream/src/HStream/Server/Handler.hs b/hstream/src/HStream/Server/Handler.hs index b8c245765..00e718d52 100644 --- a/hstream/src/HStream/Server/Handler.hs +++ b/hstream/src/HStream/Server/Handler.hs @@ -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 diff --git a/hstream/src/HStream/Server/Handler/Common.hs b/hstream/src/HStream/Server/Handler/Common.hs index 9b2957108..d209d6234 100644 --- a/hstream/src/HStream/Server/Handler/Common.hs +++ b/hstream/src/HStream/Server/Handler/Common.hs @@ -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 diff --git a/hstream/test/HStream/HandlerSpec.hs b/hstream/test/HStream/HandlerSpec.hs index 126fc6fa1..92a00cfec 100644 --- a/hstream/test/HStream/HandlerSpec.hs +++ b/hstream/test/HStream/HandlerSpec.hs @@ -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