Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-11-14 13:50:43 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-11-14 13:50:43 +0300
commitfd0e417eed8f73e6316482a2538074ecf31c3923 (patch)
treeb74f63a8134b34edb7cb29ab5d964202ecec095d /internal/source/gitlab/cache/cache_test.go
parent521a76e2348b3ada776d8031528bc81fe7693227 (diff)
Simplify how we use gitlab source retrieval contexts
Diffstat (limited to 'internal/source/gitlab/cache/cache_test.go')
-rw-r--r--internal/source/gitlab/cache/cache_test.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/internal/source/gitlab/cache/cache_test.go b/internal/source/gitlab/cache/cache_test.go
index 71212ef2..3a5a2e8f 100644
--- a/internal/source/gitlab/cache/cache_test.go
+++ b/internal/source/gitlab/cache/cache_test.go
@@ -64,7 +64,7 @@ func (cache *Cache) withTestEntry(config entryConfig, block func(*Entry)) {
domain = config.domain
}
- entry := cache.store.LoadOrCreate(context.Background(), domain)
+ entry := cache.store.LoadOrCreate(domain)
if config.retrieved {
newResponse := make(chan Lookup, 1)
@@ -210,7 +210,7 @@ func TestResolve(t *testing.T) {
lookup := cache.Resolve(ctx, "my.gitlab.com")
assert.Equal(t, uint64(0), resolver.resolutions)
- assert.EqualError(t, lookup.Error, "context timeout")
+ assert.EqualError(t, lookup.Error, "context done")
})
})
@@ -222,23 +222,24 @@ func TestResolve(t *testing.T) {
lookup := cache.Resolve(context.Background(), "my.gitlab.com")
assert.Equal(t, uint64(0), resolver.resolutions)
- assert.EqualError(t, lookup.Error, "context timeout")
+ assert.EqualError(t, lookup.Error, "context done")
})
})
- t.Run("when cache entry is evicted from cache", func(t *testing.T) {
+ t.Run("when retrieval failed because of resolution context being canceled", func(t *testing.T) {
withTestCache(resolverConfig{}, func(cache *Cache, resolver *client) {
cache.withTestEntry(entryConfig{expired: false, retrieved: false}, func(entry *Entry) {
- ctx := context.Background()
- lookup := make(chan *Lookup, 1)
- go func() { lookup <- cache.Resolve(ctx, "my.gitlab.com") }()
+ ctx, cancel := context.WithCancel(context.Background())
+
+ response := make(chan *Lookup, 1)
+ go func() { response <- cache.Resolve(ctx, "my.gitlab.com") }()
- cache.store.ReplaceOrCreate(ctx, "my.gitlab.com", newCacheEntry(ctx, "my.gitlab.com"))
+ cancel()
resolver.domain <- "my.gitlab.com"
- <-lookup
+ lookup := <-response
- assert.EqualError(t, entry.ctx.Err(), "context canceled")
+ assert.EqualError(t, lookup.Error, "context done")
})
})
})