diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-08-12 14:37:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-12 14:37:46 +0200 |
commit | b51e316bf61ff1b9e83486f2010854fb9089d9dc (patch) | |
tree | 1689d6c0fdbdad5a1e804b293eba0bdae9fb1a7e /plumbing/cache/object_test.go | |
parent | 773841734e11f0f607f6b047235f8527d475538f (diff) | |
parent | 3fd398852745b218e4346a38c98d95e5e773751d (diff) | |
download | go-git-b51e316bf61ff1b9e83486f2010854fb9089d9dc.tar.gz |
Merge pull request #544 from erizocosmico/fix/race-condition-object-lru
fix race condition on ObjectLRU
Diffstat (limited to 'plumbing/cache/object_test.go')
-rw-r--r-- | plumbing/cache/object_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/plumbing/cache/object_test.go b/plumbing/cache/object_test.go index 9359455..b38272f 100644 --- a/plumbing/cache/object_test.go +++ b/plumbing/cache/object_test.go @@ -1,7 +1,9 @@ package cache import ( + "fmt" "io" + "sync" "testing" "gopkg.in/src-d/go-git.v4/plumbing" @@ -67,6 +69,32 @@ func (s *ObjectSuite) TestClear(c *C) { c.Assert(obj, IsNil) } +func (s *ObjectSuite) TestConcurrentAccess(c *C) { + var wg sync.WaitGroup + + for i := 0; i < 1000; i++ { + wg.Add(3) + go func(i int) { + s.c.Put(newObject(fmt.Sprint(i), FileSize(i))) + wg.Done() + }(i) + + go func(i int) { + if i%30 == 0 { + s.c.Clear() + } + wg.Done() + }(i) + + go func(i int) { + s.c.Get(plumbing.NewHash(fmt.Sprint(i))) + wg.Done() + }(i) + } + + wg.Wait() +} + type dummyObject struct { hash plumbing.Hash size FileSize |