GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

integration_test.go 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // +build integration
  2. package memcached
  3. import (
  4. "os"
  5. "strings"
  6. "sync"
  7. "testing"
  8. "time"
  9. "github.com/go-kit/kit/log"
  10. "github.com/stretchr/testify/assert"
  11. "github.com/weaveworks/flux/image"
  12. "github.com/weaveworks/flux/registry"
  13. "github.com/weaveworks/flux/registry/cache"
  14. "github.com/weaveworks/flux/registry/middleware"
  15. )
  16. // memcachedIPs flag from memcached_test.go
  17. // This tests a real memcached cache and a request to a real Docker
  18. // repository. It is intended to be an end-to-end integration test for
  19. // the warmer since I had a few bugs introduced when refactoring. This
  20. // should cover against these bugs.
  21. func TestWarming_WarmerWriteCacheRead(t *testing.T) {
  22. mc := NewFixedServerMemcacheClient(MemcacheConfig{
  23. Timeout: time.Second,
  24. UpdateInterval: 1 * time.Minute,
  25. Logger: log.With(log.NewLogfmtLogger(os.Stderr), "component", "memcached"),
  26. }, strings.Fields(*memcachedIPs)...)
  27. // This repo has a stable number of images in the low tens (just
  28. // <20); more than `burst` below, but not so many that timing out
  29. // is likely.
  30. // TODO(hidde): I temporary switched this to one of our images on
  31. // Docker Hub due to Quay.io outage. It is however not guaranteed
  32. // the amount of tags for this image stays stable and in the low
  33. // tens.
  34. id, _ := image.ParseRef("docker.io/weaveworks/flagger-loadtester")
  35. logger := log.NewLogfmtLogger(os.Stderr)
  36. remote := &registry.RemoteClientFactory{
  37. Logger: log.With(logger, "component", "client"),
  38. Limiters: &middleware.RateLimiters{RPS: 10, Burst: 5},
  39. Trace: true,
  40. }
  41. r := &cache.Cache{mc}
  42. w, _ := cache.NewWarmer(remote, mc, 125)
  43. shutdown := make(chan struct{})
  44. shutdownWg := &sync.WaitGroup{}
  45. defer func() {
  46. close(shutdown)
  47. shutdownWg.Wait()
  48. }()
  49. shutdownWg.Add(1)
  50. go w.Loop(log.With(logger, "component", "warmer"), shutdown, shutdownWg, func() registry.ImageCreds {
  51. return registry.ImageCreds{
  52. id.Name: registry.NoCredentials(),
  53. }
  54. })
  55. timeout := time.NewTicker(10 * time.Second) // Shouldn't take longer than 10s
  56. tick := time.NewTicker(100 * time.Millisecond) // Check every 100ms
  57. Loop:
  58. for {
  59. select {
  60. case <-timeout.C:
  61. t.Fatal("Cache timeout")
  62. case <-tick.C:
  63. _, err := r.GetImageRepositoryMetadata(id.Name)
  64. if err == nil {
  65. break Loop
  66. }
  67. }
  68. }
  69. repoMetadata, err := r.GetImageRepositoryMetadata(id.Name)
  70. assert.NoError(t, err)
  71. assert.True(t, len(repoMetadata.Images) > 0, "Length of returned images should be > 0")
  72. assert.Equal(t, len(repoMetadata.Images), len(repoMetadata.Tags), "the length of tags and images should match")
  73. for _, tag := range repoMetadata.Tags {
  74. i, ok := repoMetadata.Images[tag]
  75. assert.True(t, ok, "tag doesn't have image information %s", tag)
  76. // None of the images should have an empty ID or a creation time of zero
  77. assert.True(t, i.ID.String() != "" && i.ID.Tag != "", "Image should not have empty name or tag. Got: %q", i.ID.String())
  78. assert.NotZero(t, i.CreatedAt, "Created time should not be zero for image %q", i.ID.String())
  79. }
  80. }