-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sharding: Add some tests for sharding codepaths #615
Open
hsanjuan
wants to merge
1
commit into
master
Choose a base branch
from
tests/shards
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,8 @@ var ( | |
ShardingDirTrickleRootCID = "QmYMbx56GFNBDAaAMchtjmWjDTdqNKCSGuFxtRosiPgJL6" | ||
|
||
// These hashes should match all the blocks produced when adding | ||
// the files resulting from GetShardingDir* | ||
// They have been obtained by adding the "shardTesting" folder | ||
// the files resulting from shardingTestDir/shadringTestTree folder. | ||
// They have been obtained by adding the that folder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
??? |
||
// to go-ipfs (with wrap=true and default parameters). Then doing | ||
// `refs -r` on the result. It contains the wrapping folder hash. | ||
ShardingDirCids = [29]string{ | ||
|
@@ -112,12 +112,33 @@ func (sth *ShardingTestHelper) GetTreeSerialFile(t *testing.T) files.File { | |
return sf | ||
} | ||
|
||
type limReaderCloser struct { | ||
io.Reader | ||
io.Closer | ||
} | ||
|
||
// GetRandFileMultiReader creates and returns a MultiFileReader for | ||
// a testing random file of the given size (in kbs). The random | ||
// file is different every time. | ||
// file is created once. Subsequent calls will read the same test file | ||
// up to the given kbs. | ||
func (sth *ShardingTestHelper) GetRandFileMultiReader(t *testing.T, kbs int) (*files.MultiFileReader, io.Closer) { | ||
st := sth.makeRandFile(t, kbs) | ||
sf, err := files.NewSerialFile("randomfile", sth.path(shardingTestFile), false, st) | ||
var sf files.File | ||
var err error | ||
path := sth.path(shardingTestFile) | ||
|
||
if !fileExists(t, path) { | ||
st := sth.makeRandFile(t, kbs) | ||
sf, err = files.NewSerialFile("randomfile", path, false, st) | ||
} else { | ||
f, err2 := os.Open(path) | ||
if err2 != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
limReader := io.LimitReader(f, int64(kbs*1024)) | ||
sf, err = files.NewReaderPathFile("randomfile", path, limReaderCloser{limReader, f}, nil) | ||
} | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -144,6 +165,15 @@ func folderExists(t *testing.T, path string) bool { | |
return true | ||
} | ||
|
||
func fileExists(t *testing.T, path string) bool { | ||
if _, err := os.Stat(path); os.IsNotExist(err) { | ||
return false | ||
} else if err != nil { | ||
t.Fatal(err) | ||
} | ||
return true | ||
} | ||
|
||
func makeDir(t *testing.T, path string) { | ||
if !folderExists(t, path) { | ||
err := os.MkdirAll(path, os.ModePerm) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if each of these tests could have a bit more explanation as to what they are testing as the testcase is hard to grok from the code.