Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
5dd32d64
Commit
5dd32d64
authored
Dec 05, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for running gc during an add
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
c49dcffc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
1 deletion
+131
-1
core/coreunix/add.go
core/coreunix/add.go
+1
-1
core/coreunix/add_test.go
core/coreunix/add_test.go
+130
-0
No files found.
core/coreunix/add.go
View file @
5dd32d64
...
...
@@ -155,7 +155,7 @@ func (params *Adder) PinRoot() error {
return
nil
}
rnk
,
err
:=
root
.
Key
(
)
rnk
,
err
:=
params
.
node
.
DAG
.
Add
(
root
)
if
err
!=
nil
{
return
err
}
...
...
core/coreunix/add_test.go
View file @
5dd32d64
package
coreunix
import
(
"bytes"
"io"
"io/ioutil"
"testing"
"time"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
"github.com/ipfs/go-ipfs/blocks/key"
"github.com/ipfs/go-ipfs/commands/files"
"github.com/ipfs/go-ipfs/core"
dag
"github.com/ipfs/go-ipfs/merkledag"
"github.com/ipfs/go-ipfs/pin/gc"
"github.com/ipfs/go-ipfs/repo"
"github.com/ipfs/go-ipfs/repo/config"
"github.com/ipfs/go-ipfs/util/testutil"
...
...
@@ -29,3 +37,125 @@ func TestAddRecursive(t *testing.T) {
t
.
Fatal
(
"keys do not match: "
,
k
)
}
}
func
TestAddGCLive
(
t
*
testing
.
T
)
{
r
:=
&
repo
.
Mock
{
C
:
config
.
Config
{
Identity
:
config
.
Identity
{
PeerID
:
"Qmfoo"
,
// required by offline node
},
},
D
:
testutil
.
ThreadSafeCloserMapDatastore
(),
}
node
,
err
:=
core
.
NewNode
(
context
.
Background
(),
&
core
.
BuildCfg
{
Repo
:
r
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
errs
:=
make
(
chan
error
)
out
:=
make
(
chan
interface
{})
adder
,
err
:=
NewAdder
(
context
.
Background
(),
node
,
out
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
dataa
:=
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
"testfileA"
))
rfa
:=
files
.
NewReaderFile
(
"a"
,
"a"
,
dataa
,
nil
)
// make two files with pipes so we can 'pause' the add for timing of the test
piper
,
pipew
:=
io
.
Pipe
()
hangfile
:=
files
.
NewReaderFile
(
"b"
,
"b"
,
piper
,
nil
)
datad
:=
ioutil
.
NopCloser
(
bytes
.
NewBufferString
(
"testfileD"
))
rfd
:=
files
.
NewReaderFile
(
"d"
,
"d"
,
datad
,
nil
)
slf
:=
files
.
NewSliceFile
(
"files"
,
"files"
,
[]
files
.
File
{
rfa
,
hangfile
,
rfd
})
addDone
:=
make
(
chan
struct
{})
go
func
()
{
defer
close
(
addDone
)
defer
close
(
out
)
err
:=
adder
.
AddFile
(
slf
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}()
addedHashes
:=
make
(
map
[
string
]
struct
{})
select
{
case
o
:=
<-
out
:
addedHashes
[
o
.
(
*
AddedObject
)
.
Hash
]
=
struct
{}{}
case
<-
addDone
:
t
.
Fatal
(
"add shouldnt complete yet"
)
}
var
gcout
<-
chan
key
.
Key
gcstarted
:=
make
(
chan
struct
{})
go
func
()
{
defer
close
(
gcstarted
)
gcchan
,
err
:=
gc
.
GC
(
context
.
Background
(),
node
.
Blockstore
,
node
.
Pinning
)
if
err
!=
nil
{
log
.
Error
(
"GC ERROR:"
,
err
)
errs
<-
err
return
}
gcout
=
gcchan
}()
// gc shouldnt start until we let the add finish its current file.
pipew
.
Write
([]
byte
(
"some data for file b"
))
select
{
case
<-
gcstarted
:
t
.
Fatal
(
"gc shouldnt have started yet"
)
case
err
:=
<-
errs
:
t
.
Fatal
(
err
)
default
:
}
time
.
Sleep
(
time
.
Millisecond
*
100
)
// make sure gc gets to requesting lock
// finish write and unblock gc
pipew
.
Close
()
// receive next object from adder
select
{
case
o
:=
<-
out
:
addedHashes
[
o
.
(
*
AddedObject
)
.
Hash
]
=
struct
{}{}
case
err
:=
<-
errs
:
t
.
Fatal
(
err
)
}
select
{
case
<-
gcstarted
:
case
err
:=
<-
errs
:
t
.
Fatal
(
err
)
}
for
k
:=
range
gcout
{
if
_
,
ok
:=
addedHashes
[
k
.
B58String
()];
ok
{
t
.
Fatal
(
"gc'ed a hash we just added"
)
}
}
var
last
key
.
Key
for
a
:=
range
out
{
// wait for it to finish
last
=
key
.
B58KeyDecode
(
a
.
(
*
AddedObject
)
.
Hash
)
}
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
5
)
defer
cancel
()
root
,
err
:=
node
.
DAG
.
Get
(
ctx
,
last
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
dag
.
EnumerateChildren
(
ctx
,
node
.
DAG
,
root
,
key
.
NewKeySet
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
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