Skip to content

Commit

Permalink
chore: add epsilon sleep durations/reduce default ttl on tests (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta authored Sep 10, 2024
1 parent 8c175f4 commit b1241a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions momento/batch_set_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var _ = Describe("cache-client get-batch set-batch", Label(CACHE_SERVICE_LABEL),
setBatchResp, setBatchErr := sharedContext.Client.SetBatch(sharedContext.Ctx, &SetBatchRequest{
CacheName: sharedContext.DefaultCacheName,
Items: items,
Ttl: 1 * time.Second,
Ttl: 500 * time.Millisecond,
})
Expect(setBatchErr).To(BeNil())
Expect(setBatchResp).To(BeAssignableToTypeOf(responses.SetBatchSuccess{}))
Expand All @@ -118,7 +118,7 @@ var _ = Describe("cache-client get-batch set-batch", Label(CACHE_SERVICE_LABEL),
Expect(setResp).To(BeAssignableToTypeOf(&responses.SetSuccess{}))
}

time.Sleep(3 * time.Second)
time.Sleep(2 * time.Second)

getBatchResp, getBatchErr := sharedContext.Client.GetBatch(sharedContext.Ctx, &GetBatchRequest{
CacheName: sharedContext.DefaultCacheName,
Expand Down
13 changes: 9 additions & 4 deletions momento/dictionary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,17 @@ var _ = Describe("cache-client dictionary-methods", Label(CACHE_SERVICE_LABEL),

It("returns a miss for the collection", func() {
dictionaryName := NewRandomString()
var cacheTtl = 500 * time.Millisecond
Expect(
sharedContext.Client.DictionarySetFields(sharedContext.Ctx, &DictionarySetFieldsRequest{
CacheName: sharedContext.CacheName,
DictionaryName: dictionaryName,
Elements: DictionaryElementsFromMapStringValue(
map[string]Value{"myField1": String("myValue1"), "myField2": String("myValue2")},
),
Ttl: &CollectionTtl{
Ttl: cacheTtl,
},
}),
).Error().To(BeNil())

Expand All @@ -880,7 +884,7 @@ var _ = Describe("cache-client dictionary-methods", Label(CACHE_SERVICE_LABEL),
}),
).To(BeAssignableToTypeOf(&DictionaryFetchHit{}))

time.Sleep(sharedContext.DefaultTtl)
time.Sleep(1 * time.Second)

Expect(
sharedContext.Client.DictionaryFetch(sharedContext.Ctx, &DictionaryFetchRequest{
Expand Down Expand Up @@ -938,6 +942,7 @@ var _ = Describe("cache-client dictionary-methods", Label(CACHE_SERVICE_LABEL),

It("is ignored if refresh ttl is false", func() {
dictionaryName := NewRandomString()
var cacheTtl = 500 * time.Millisecond

// Create a new dictionary with a TTL
Expect(sharedContext.Client.DictionarySetFields(sharedContext.Ctx, &DictionarySetFieldsRequest{
Expand All @@ -947,7 +952,7 @@ var _ = Describe("cache-client dictionary-methods", Label(CACHE_SERVICE_LABEL),
map[string]Value{"myField1": String("myValue1"), "myField2": String("myValue2")},
),
Ttl: &CollectionTtl{
Ttl: sharedContext.DefaultTtl,
Ttl: cacheTtl,
RefreshTtl: false,
},
})).To(BeAssignableToTypeOf(&DictionarySetFieldsSuccess{}))
Expand All @@ -960,13 +965,13 @@ var _ = Describe("cache-client dictionary-methods", Label(CACHE_SERVICE_LABEL),
Field: String("myField3"),
Value: String("myValue3"),
Ttl: &CollectionTtl{
Ttl: sharedContext.DefaultTtl + time.Second*60,
Ttl: cacheTtl + time.Second*60,
RefreshTtl: false,
},
}),
).To(BeAssignableToTypeOf(&DictionarySetFieldSuccess{}))

time.Sleep(sharedContext.DefaultTtl)
time.Sleep(1 * time.Second)

Expect(
sharedContext.Client.DictionaryFetch(sharedContext.Ctx, &DictionaryFetchRequest{
Expand Down
7 changes: 4 additions & 3 deletions momento/scalar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ var _ = Describe("cache-client scalar-methods", Label(CACHE_SERVICE_LABEL), func
}),
).To(BeAssignableToTypeOf(&GetHit{}))

time.Sleep(sharedContext.DefaultTtl)
time.Sleep(sharedContext.DefaultTtl + 100*time.Millisecond)

Expect(
sharedContext.Client.Get(sharedContext.Ctx, &GetRequest{
Expand Down Expand Up @@ -760,7 +760,7 @@ var _ = Describe("cache-client scalar-methods", Label(CACHE_SERVICE_LABEL), func
}),
).To(BeAssignableToTypeOf(&GetHit{}))

time.Sleep(sharedContext.DefaultTtl)
time.Sleep(sharedContext.DefaultTtl + 100*time.Millisecond)

Expect(
sharedContext.Client.Get(sharedContext.Ctx, &GetRequest{
Expand Down Expand Up @@ -933,14 +933,15 @@ var _ = Describe("cache-client scalar-methods", Label(CACHE_SERVICE_LABEL), func
CacheName: cacheName,
Key: key,
Value: value,
Ttl: 4 * time.Second,
}),
).To(BeAssignableToTypeOf(&SetSuccess{}))

Expect(
client.DecreaseTtl(sharedContext.Ctx, &DecreaseTtlRequest{
CacheName: cacheName,
Key: key,
Ttl: 2 * time.Second,
Ttl: 1*time.Second + 500*time.Millisecond,
}),
).To(BeAssignableToTypeOf(&DecreaseTtlSet{}))

Expand Down
3 changes: 3 additions & 0 deletions momento/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ var _ = Describe("cache-client set-methods", Label(CACHE_SERVICE_LABEL), func()
CacheName: sharedContext.CacheName,
SetName: setName,
Element: String("hello"),
Ttl: &utils.CollectionTtl{
Ttl: 500 * time.Millisecond,
},
}),
).Error().To(BeNil())

Expand Down

0 comments on commit b1241a9

Please sign in to comment.