mhart / kinesalite

An implementation of Amazon's Kinesis built on LevelDB
MIT License
808 stars 86 forks source link

delete stream claims to be successful, but doesn't really delete for ~500ms #41

Closed jonnycundall closed 7 years ago

jonnycundall commented 7 years ago

I'm using windows, calling AWS .Net API in c#. Apologies if this is really an issue with the AWS .Net API. I wanted to ensure there was nothing in my testing streams before each test, by deleting then recreating them. I assumed that if I get a OK response from my deleting request the stream will be deleted. But if I don't introduce a pause between deleting and creating a stream of the same name, I get a ResourceInUseException

my c# code to give you an idea

        public void CreateCleanStreams(string streamName)
        {
            if (_amazonKinesisClient.ListStreams().StreamNames.Contains(streamName))
            {
                var deleteStreamResponse = _amazonKinesisClient.DeleteStream(new DeleteStreamRequest
                {
                    StreamName = streamName
                });
                Assert.AreEqual(HttpStatusCode.OK, deleteStreamResponse.HttpStatusCode);
            }
            Thread.Sleep(500);//see exception handling below
            try
            {
                var createStreamResponse  = _amazonKinesisClient.CreateStream(new CreateStreamRequest
                {
                    StreamName = streamName,
                    ShardCount = 1
                });
                Assert.AreEqual(HttpStatusCode.OK, createStreamResponse.HttpStatusCode);
            }
            catch (ResourceInUseException e)
            {
                Assert.Fail("even though we told kinesalite to delete the stream, and it says it did, it needs a bit more time to really delete it");
            }

        }
mhart commented 7 years ago

This is by design – to emulate the live Kinesis services (they will also return OK, but won't actually complete deleting until a while later).

You can modify this timeout as documented here: https://github.com/mhart/kinesalite#example

jonnycundall commented 7 years ago

Thanks for your swift and clear response!