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
37ce1863
Commit
37ce1863
authored
Oct 30, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test splitting is deterministic. (it is)
parent
13f00abc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
importer/chunk/splitting_test.go
importer/chunk/splitting_test.go
+53
-0
No files found.
importer/chunk/splitting_test.go
0 → 100644
View file @
37ce1863
package
chunk
import
(
"bytes"
"crypto/rand"
"testing"
)
func
randBuf
(
t
*
testing
.
T
,
size
int
)
[]
byte
{
buf
:=
make
([]
byte
,
size
)
if
_
,
err
:=
rand
.
Read
(
buf
);
err
!=
nil
{
t
.
Fatal
(
"failed to read enough randomness"
)
}
return
buf
}
func
copyBuf
(
buf
[]
byte
)
[]
byte
{
cpy
:=
make
([]
byte
,
len
(
buf
))
copy
(
cpy
,
buf
)
return
cpy
}
func
TestSizeSplitterIsDeterministic
(
t
*
testing
.
T
)
{
test
:=
func
()
{
bufR
:=
randBuf
(
t
,
10000000
)
// crank this up to satisfy yourself.
bufA
:=
copyBuf
(
bufR
)
bufB
:=
copyBuf
(
bufR
)
chunksA
:=
DefaultSplitter
.
Split
(
bytes
.
NewReader
(
bufA
))
chunksB
:=
DefaultSplitter
.
Split
(
bytes
.
NewReader
(
bufB
))
for
n
:=
0
;
;
n
++
{
a
,
moreA
:=
<-
chunksA
b
,
moreB
:=
<-
chunksB
if
!
moreA
{
if
moreB
{
t
.
Fatal
(
"A ended, B didnt."
)
}
return
}
if
!
bytes
.
Equal
(
a
,
b
)
{
t
.
Fatalf
(
"chunk %d not equal"
,
n
)
}
}
}
for
run
:=
0
;
run
<
1
;
run
++
{
// crank this up to satisfy yourself.
test
()
}
}
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