Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
a342f89c
Unverified
Commit
a342f89c
authored
Mar 25, 2021
by
acud
Committed by
GitHub
Mar 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
localstore: change pin gc test to reduce flakiness (#1491)
parent
d9bb759d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
14 deletions
+40
-14
gc_test.go
pkg/localstore/gc_test.go
+40
-14
No files found.
pkg/localstore/gc_test.go
View file @
a342f89c
...
...
@@ -61,6 +61,13 @@ func testDBCollectGarbageWorker(t *testing.T) {
var
closed
chan
struct
{}
testHookCollectGarbageChan
:=
make
(
chan
uint64
)
t
.
Cleanup
(
setTestHookCollectGarbage
(
func
(
collectedCount
uint64
)
{
// don't trigger if we haven't collected anything - this may
// result in a race condition when we inspect the gcsize below,
// causing the database to shut down while the cleanup to happen
// before the correct signal has been communicated here.
if
collectedCount
==
0
{
return
}
select
{
case
testHookCollectGarbageChan
<-
collectedCount
:
case
<-
closed
:
...
...
@@ -151,6 +158,14 @@ func TestPinGC(t *testing.T) {
var
closed
chan
struct
{}
testHookCollectGarbageChan
:=
make
(
chan
uint64
)
t
.
Cleanup
(
setTestHookCollectGarbage
(
func
(
collectedCount
uint64
)
{
// don't trigger if we haven't collected anything - this may
// result in a race condition when we inspect the gcsize below,
// causing the database to shut down while the cleanup to happen
// before the correct signal has been communicated here.
if
collectedCount
==
0
{
return
}
select
{
case
testHookCollectGarbageChan
<-
collectedCount
:
case
<-
closed
:
...
...
@@ -169,7 +184,13 @@ func TestPinGC(t *testing.T) {
for
i
:=
0
;
i
<
chunkCount
;
i
++
{
ch
:=
generateTestRandomChunk
()
_
,
err
:=
db
.
Put
(
context
.
Background
(),
storage
.
ModePutUpload
,
ch
)
mode
:=
storage
.
ModePutUpload
if
i
<
pinChunksCount
{
mode
=
storage
.
ModePutUploadPin
pinAddrs
=
append
(
pinAddrs
,
ch
.
Address
())
}
_
,
err
:=
db
.
Put
(
context
.
Background
(),
mode
,
ch
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -178,25 +199,16 @@ func TestPinGC(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
addrs
=
append
(
addrs
,
ch
.
Address
())
// Pin the chunks at the beginning to make sure they are not removed by GC
if
i
<
pinChunksCount
{
err
=
db
.
Set
(
context
.
Background
(),
storage
.
ModeSetPin
,
ch
.
Address
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pinAddrs
=
append
(
pinAddrs
,
ch
.
Address
())
}
}
gcTarget
:=
db
.
gcTarget
()
gcTarget
:=
db
.
gcTarget
()
t
.
Log
(
gcTarget
)
for
{
select
{
case
<-
testHookCollectGarbageChan
:
case
<-
time
.
After
(
10
*
time
.
Second
)
:
t
.
Error
(
"collect garbage timeout"
)
t
.
Fatal
(
"collect garbage timeout"
)
}
gcSize
,
err
:=
db
.
gcSize
.
Get
()
if
err
!=
nil
{
...
...
@@ -209,7 +221,7 @@ func TestPinGC(t *testing.T) {
t
.
Run
(
"pin Index count"
,
newItemsCountTest
(
db
.
pinIndex
,
pinChunksCount
))
t
.
Run
(
"gc exclude index count"
,
newItemsCountTest
(
db
.
gcExcludeIndex
,
0
))
t
.
Run
(
"gc exclude index count"
,
newItemsCountTest
(
db
.
gcExcludeIndex
,
pinChunksCount
))
t
.
Run
(
"pull index count"
,
newItemsCountTest
(
db
.
pullIndex
,
int
(
gcTarget
)
+
pinChunksCount
))
...
...
@@ -308,6 +320,13 @@ func TestDB_collectGarbageWorker_withRequests(t *testing.T) {
testHookCollectGarbageChan
:=
make
(
chan
uint64
)
defer
setTestHookCollectGarbage
(
func
(
collectedCount
uint64
)
{
// don't trigger if we haven't collected anything - this may
// result in a race condition when we inspect the gcsize below,
// causing the database to shut down while the cleanup to happen
// before the correct signal has been communicated here.
if
collectedCount
==
0
{
return
}
testHookCollectGarbageChan
<-
collectedCount
})()
...
...
@@ -624,6 +643,13 @@ func TestPinSyncAndAccessPutSetChunkMultipleTimes(t *testing.T) {
var
closed
chan
struct
{}
testHookCollectGarbageChan
:=
make
(
chan
uint64
)
t
.
Cleanup
(
setTestHookCollectGarbage
(
func
(
collectedCount
uint64
)
{
// don't trigger if we haven't collected anything - this may
// result in a race condition when we inspect the gcsize below,
// causing the database to shut down while the cleanup to happen
// before the correct signal has been communicated here.
if
collectedCount
==
0
{
return
}
select
{
case
testHookCollectGarbageChan
<-
collectedCount
:
case
<-
closed
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment