-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Move coreapi tests to the interface #5865
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac529e7
coreapi: don't touch IpfsNode in tests
magik6k e0e2c70
coreapi: move tests to interface subpackage
magik6k 5a019ba
coreapi: run tests from interface
magik6k 94724fd
coreapi: Interface for external test providers
magik6k cf043b9
coreapi: make sure to cancel context in tests
magik6k 44fc750
coreapi: don't panic as much in tests
magik6k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface" | ||
) | ||
|
||
func (tp *provider) makeAPI(ctx context.Context) (coreiface.CoreAPI, error) { | ||
api, err := tp.MakeAPISwarm(ctx, false, 1) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return api[0], nil | ||
} | ||
|
||
type Provider interface { | ||
// Make creates n nodes. fullIdentity set to false can be ignored | ||
MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) | ||
} | ||
|
||
func (tp *provider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int) ([]coreiface.CoreAPI, error) { | ||
tp.apis <- 1 | ||
go func() { | ||
<-ctx.Done() | ||
tp.apis <- -1 | ||
}() | ||
|
||
return tp.Provider.MakeAPISwarm(ctx, fullIdentity, n) | ||
} | ||
|
||
type provider struct { | ||
Provider | ||
|
||
apis chan int | ||
} | ||
|
||
func TestApi(p Provider) func(t *testing.T) { | ||
running := 1 | ||
apis := make(chan int) | ||
zeroRunning := make(chan struct{}) | ||
go func() { | ||
for i := range apis { | ||
running += i | ||
if running < 1 { | ||
close(zeroRunning) | ||
return | ||
} | ||
} | ||
}() | ||
|
||
tp := &provider{Provider: p, apis: apis} | ||
|
||
return func(t *testing.T) { | ||
t.Run("Block", tp.TestBlock) | ||
t.Run("Dag", tp.TestDag) | ||
t.Run("Dht", tp.TestDht) | ||
t.Run("Key", tp.TestKey) | ||
t.Run("Name", tp.TestName) | ||
t.Run("Object", tp.TestObject) | ||
t.Run("Path", tp.TestPath) | ||
t.Run("Pin", tp.TestPin) | ||
t.Run("PubSub", tp.TestPubSub) | ||
t.Run("Unixfs", tp.TestUnixfs) | ||
|
||
apis <- -1 | ||
t.Run("TestsCancelCtx", func(t *testing.T) { | ||
select { | ||
case <-zeroRunning: | ||
case <-time.After(time.Second): | ||
t.Errorf("%d test swarms(s) not closed", running) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.
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.
What's the pattern for the replacement of Error with Fatal? Are we testing the first use of the CoreAPI generally?
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.
I think I understand - it's an existing inconsistency and you didn't want to change them wholesale.
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.
TBH I just started changing them here as I was working on running tests in go-ipfs-http-api and this got committed. I'll commit more of those fixes in another PR.