Repository: allegro/bigcache
Pull request #223 (2020-05-29 04:58:50)

Reset full to false when pop from bytes queue
When byte queue is full, it will set `queue.full=true` but when evict and pop entry from queue, it does not set to false again. It causes bigcache cannot insert new entries once the queue is full.

This commit set `queue.full=false` when pop entry from queue, and add a test case which failed in current master https://github.com/allegro/bigcache/commit/ccdbc60304ad5ede288fea0a3d37ce4bae17b6db and passed in this commit.

Related to issue https://github.com/allegro/bigcache/issues/214
And it seems the same problem in Pull Request https://github.com/allegro/bigcache/pull/218


codecov-commenter: # [Codecov](https://codecov.io/gh/allegro/bigcache/pull/223?src=pr&el=h1) Report
> Merging [#223](https://codecov.io/gh/allegro/bigcache/pull/223?src=pr&el=desc) into [master](https://codecov.io/gh/allegro/bigcache/commit/ccdbc60304ad5ede288fea0a3d37ce4bae17b6db&el=desc) will **decrease** coverage by `1.52%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/allegro/bigcache/pull/223/graphs/tree.svg?width=650&height=150&src=pr&token=NRx0gXD6he)](https://codecov.io/gh/allegro/bigcache/pull/223?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #223      +/-   ##
==========================================
- Coverage   90.61%   89.09%   -1.53%     
==========================================
  Files          15       15              
  Lines         714      715       +1     
==========================================
- Hits          647      637      -10     
- Misses         58       66       +8     
- Partials        9       12       +3     
```


| [Impacted Files](https://codecov.io/gh/allegro/bigcache/pull/223?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [queue/bytes\_queue.go](https://codecov.io/gh/allegro/bigcache/pull/223/diff?src=pr&el=tree#diff-cXVldWUvYnl0ZXNfcXVldWUuZ28=) | `88.80% <100.00%> (+0.09%)` | :arrow_up: |
| [shard.go](https://codecov.io/gh/allegro/bigcache/pull/223/diff?src=pr&el=tree#diff-c2hhcmQuZ28=) | `86.52% <0.00%> (-4.79%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/allegro/bigcache/pull/223?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/allegro/bigcache/pull/223?src=pr&el=footer). Last update [ccdbc60...8d7fc3a](https://codecov.io/gh/allegro/bigcache/pull/223?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/queue/bytes_queue.go b/queue/bytes_queue.go
index b45387b..0984980 100644
--- a/queue/bytes_queue.go
+++ b/queue/bytes_queue.go
@@ -173,6 +173,8 @@ func (q *BytesQueue) Pop() ([]byte, error) {
 		q.rightMargin = q.tail
 	}
 
+	q.full = false
+
 	return data, nil
 }
 


Test patch:
diff --git a/bigcache_test.go b/bigcache_test.go
index 4bf28a5..a28cc9f 100644
--- a/bigcache_test.go
+++ b/bigcache_test.go
@@ -490,6 +490,33 @@ func TestCacheCapacity(t *testing.T) {
 	assertEqual(t, 40960, cache.Capacity())
 }
 
+func TestRemoveEntriesWhenShardIsFull(t *testing.T) {
+	t.Parallel()
+
+	// given
+	cache, _ := NewBigCache(Config{
+		Shards:             1,
+		LifeWindow:         100 * time.Second,
+		MaxEntriesInWindow: 100,
+		MaxEntrySize:       256,
+		HardMaxCacheSize:   1,
+	})
+
+	value := blob('a', 1024*300)
+
+	// when
+	cache.Set("key", value)
+	cache.Set("key", value)
+	cache.Set("key", value)
+	cache.Set("key", value)
+	cache.Set("key", value)
+	cachedValue, err := cache.Get("key")
+
+	// then
+	noError(t, err)
+	assertEqual(t, value, cachedValue)
+}
+
 func TestCacheStats(t *testing.T) {
 	t.Parallel()