X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7ea61e9c890706e1ac020143072ea0a6e17894ab..69158dc93fdfec57279ba227f872f3a7c01c4e78:/services/keepstore/bufferpool_test.go diff --git a/services/keepstore/bufferpool_test.go b/services/keepstore/bufferpool_test.go index b2f63b1abb..13e1cb4f33 100644 --- a/services/keepstore/bufferpool_test.go +++ b/services/keepstore/bufferpool_test.go @@ -1,26 +1,34 @@ -package main +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +package keepstore import ( - . "gopkg.in/check.v1" - "testing" + "context" "time" + + "git.arvados.org/arvados.git/sdk/go/ctxlog" + . "gopkg.in/check.v1" ) -// Gocheck boilerplate -func TestBufferPool(t *testing.T) { - TestingT(t) -} var _ = Suite(&BufferPoolSuite{}) -type BufferPoolSuite struct {} + +type BufferPoolSuite struct{} // Initialize a default-sized buffer pool for the benefit of test // suites that don't run main(). func init() { - bufs = newBufferPool(maxBuffers, BLOCKSIZE) + bufs = newBufferPool(ctxlog.FromContext(context.Background()), 12, BlockSize) +} + +// Restore sane default after bufferpool's own tests +func (s *BufferPoolSuite) TearDownTest(c *C) { + bufs = newBufferPool(ctxlog.FromContext(context.Background()), 12, BlockSize) } func (s *BufferPoolSuite) TestBufferPoolBufSize(c *C) { - bufs := newBufferPool(2, 10) + bufs := newBufferPool(ctxlog.TestLogger(c), 2, 10) b1 := bufs.Get(1) bufs.Get(2) bufs.Put(b1) @@ -29,14 +37,14 @@ func (s *BufferPoolSuite) TestBufferPoolBufSize(c *C) { } func (s *BufferPoolSuite) TestBufferPoolUnderLimit(c *C) { - bufs := newBufferPool(3, 10) + bufs := newBufferPool(ctxlog.TestLogger(c), 3, 10) b1 := bufs.Get(10) bufs.Get(10) testBufferPoolRace(c, bufs, b1, "Get") } func (s *BufferPoolSuite) TestBufferPoolAtLimit(c *C) { - bufs := newBufferPool(2, 10) + bufs := newBufferPool(ctxlog.TestLogger(c), 2, 10) b1 := bufs.Get(10) bufs.Get(10) testBufferPoolRace(c, bufs, b1, "Put") @@ -50,7 +58,7 @@ func testBufferPoolRace(c *C, bufs *bufferPool, unused []byte, expectWin string) race <- "Get" }() go func() { - time.Sleep(10*time.Millisecond) + time.Sleep(10 * time.Millisecond) bufs.Put(unused) race <- "Put" }() @@ -60,7 +68,7 @@ func testBufferPoolRace(c *C, bufs *bufferPool, unused []byte, expectWin string) } func (s *BufferPoolSuite) TestBufferPoolReuse(c *C) { - bufs := newBufferPool(2, 10) + bufs := newBufferPool(ctxlog.TestLogger(c), 2, 10) bufs.Get(10) last := bufs.Get(10) // The buffer pool is allowed to throw away unused buffers @@ -81,5 +89,5 @@ func (s *BufferPoolSuite) TestBufferPoolReuse(c *C) { } last = next } - c.Check(reuses > allocs * 95/100, Equals, true) + c.Check(reuses > allocs*95/100, Equals, true) }