Skip to content

Commit

Permalink
Add hokey test
Browse files Browse the repository at this point in the history
- I'm just leaving this in here in case I need to debug this scenario
  again.
  • Loading branch information
jdeppe-pivotal committed Apr 13, 2017
1 parent 419f7c2 commit 17b0e62
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/s3proxy/blob_cache/cache_suite_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
package blob_cache
package blob_cache_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestBlobCache(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Blob Cache Suite")
}
67 changes: 66 additions & 1 deletion src/s3proxy/blob_cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,66 @@
package blob_cache
package blob_cache_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"os"
"github.com/karlseguin/ccache"
"s3proxy/fakes"
"s3proxy/blob_cache"
"golang.org/x/net/context"
"s3proxy/context"
"s3proxy/source"
"time"
"sync"
"io"
"fmt"
)

var _ = Describe("Testing blob cache", func() {
Context("Sanity", func() {
It("Just works", func() {
cacheDir, err := ioutil.TempDir("", "cached-")
Expect(err).To(BeNil())
defer os.RemoveAll(cacheDir)

bc := ccache.Layered(ccache.Configure())
fus := fakes.NewFakeUpstreamSource(cacheDir, bc)
cache := blob_cache.NewS3Cache(bc, fus, cacheDir, 60)

meta := &source.Meta {
Size: 1,
Expires: time.Now(),
}

cache.AddMeta(meta, "/cached/1000000")

wg := sync.WaitGroup{}
wg.Add(3)

var i uint64
for i = 0; i < 3; i++ {
x := i
go func() {
ctx := context.WithValue(context.Background(), 0, &cache_context.Context{x})
r, _ := cache.Get(ctx, "/cached/1000000")
var err error
buf := make([]byte, 65536)
var total int
var n int
for {
n, err = r.Read(buf)
total += n
if err != nil && err == io.EOF {
fmt.Printf("err: %s\n", err)
break
}
}
fmt.Printf("[%d] --->>> read %d\n", x, total)
wg.Done()
}()
}
wg.Wait()
})
})
})

0 comments on commit 17b0e62

Please sign in to comment.