-
Notifications
You must be signed in to change notification settings - Fork 17
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
Cleanup errors #88
Merged
hannahhoward
merged 3 commits into
feat/add-bool-to-revalidator-interfaces
from
feat/cleanup-errors
Sep 29, 2020
Merged
Cleanup errors #88
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
|
@@ -593,21 +593,21 @@ type retrievalRevalidator struct { | |
finalVoucher datatransfer.VoucherResult | ||
} | ||
|
||
func (r *retrievalRevalidator) OnPullDataSent(chid datatransfer.ChannelID, additionalBytesSent uint64) (datatransfer.VoucherResult, error) { | ||
func (r *retrievalRevalidator) OnPullDataSent(chid datatransfer.ChannelID, additionalBytesSent uint64) (bool, datatransfer.VoucherResult, error) { | ||
r.dataSoFar += additionalBytesSent | ||
if r.providerPausePoint < len(r.pausePoints) && | ||
r.dataSoFar >= r.pausePoints[r.providerPausePoint] { | ||
r.providerPausePoint++ | ||
return testutil.NewFakeDTType(), datatransfer.ErrPause | ||
return true, testutil.NewFakeDTType(), datatransfer.ErrPause | ||
} | ||
return nil, nil | ||
return true, nil, nil | ||
} | ||
|
||
func (r *retrievalRevalidator) OnPushDataReceived(chid datatransfer.ChannelID, additionalBytesReceived uint64) (datatransfer.VoucherResult, error) { | ||
return nil, nil | ||
func (r *retrievalRevalidator) OnPushDataReceived(chid datatransfer.ChannelID, additionalBytesReceived uint64) (bool, datatransfer.VoucherResult, error) { | ||
return false, nil, nil | ||
} | ||
func (r *retrievalRevalidator) OnComplete(chid datatransfer.ChannelID) (datatransfer.VoucherResult, error) { | ||
return r.finalVoucher, datatransfer.ErrPause | ||
func (r *retrievalRevalidator) OnComplete(chid datatransfer.ChannelID) (bool, datatransfer.VoucherResult, error) { | ||
return true, r.finalVoucher, datatransfer.ErrPause | ||
} | ||
|
||
func TestSimulatedRetrievalFlow(t *testing.T) { | ||
|
@@ -890,6 +890,83 @@ func TestPauseAndResume(t *testing.T) { | |
} | ||
} | ||
|
||
func TestUnrecognizedVoucherRoundTrip(t *testing.T) { | ||
ctx := context.Background() | ||
testCases := map[string]bool{ | ||
"push requests": false, | ||
"pull requests": true, | ||
} | ||
for testCase, isPull := range testCases { | ||
t.Run(testCase, func(t *testing.T) { | ||
// ctx, cancel := context.WithTimeout(ctx, 5*time.Second) | ||
// defer cancel() | ||
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. nit: dead code. |
||
|
||
gsData := testutil.NewGraphsyncTestingData(ctx, t) | ||
host1 := gsData.Host1 // initiator, data sender | ||
host2 := gsData.Host2 // data recipient | ||
|
||
tp1 := gsData.SetupGSTransportHost1() | ||
tp2 := gsData.SetupGSTransportHost2() | ||
|
||
dt1, err := NewDataTransfer(gsData.DtDs1, gsData.DtNet1, tp1, gsData.StoredCounter1) | ||
require.NoError(t, err) | ||
err = dt1.Start(ctx) | ||
require.NoError(t, err) | ||
dt2, err := NewDataTransfer(gsData.DtDs2, gsData.DtNet2, tp2, gsData.StoredCounter2) | ||
require.NoError(t, err) | ||
err = dt2.Start(ctx) | ||
require.NoError(t, err) | ||
|
||
finished := make(chan struct{}, 2) | ||
errChan := make(chan string, 2) | ||
opened := make(chan struct{}, 2) | ||
var subscriber datatransfer.Subscriber = func(event datatransfer.Event, channelState datatransfer.ChannelState) { | ||
if channelState.Status() == datatransfer.Failed { | ||
finished <- struct{}{} | ||
} | ||
if event.Code == datatransfer.Error { | ||
errChan <- channelState.Message() | ||
} | ||
if event.Code == datatransfer.Open { | ||
opened <- struct{}{} | ||
} | ||
} | ||
dt1.SubscribeToEvents(subscriber) | ||
dt2.SubscribeToEvents(subscriber) | ||
voucher := testutil.FakeDTType{Data: "applesauce"} | ||
|
||
root, _ := testutil.LoadUnixFSFile(ctx, t, gsData.DagService1) | ||
rootCid := root.(cidlink.Link).Cid | ||
|
||
if isPull { | ||
_, err = dt2.OpenPullDataChannel(ctx, host1.ID(), &voucher, rootCid, gsData.AllSelector) | ||
} else { | ||
_, err = dt1.OpenPushDataChannel(ctx, host2.ID(), &voucher, rootCid, gsData.AllSelector) | ||
} | ||
require.NoError(t, err) | ||
opens := 0 | ||
var errMessages []string | ||
finishes := 0 | ||
for opens < 1 || finishes < 1 { | ||
select { | ||
case <-ctx.Done(): | ||
t.Fatal("Did not complete succcessful data transfer") | ||
case <-finished: | ||
finishes++ | ||
case <-opened: | ||
opens++ | ||
case errMessage := <-errChan: | ||
require.Equal(t, errMessage, datatransfer.ErrRejected.Error()) | ||
errMessages = append(errMessages, errMessage) | ||
if len(errMessages) > 1 { | ||
t.Fatal("too many errors") | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestDataTransferSubscribing(t *testing.T) { | ||
// create network | ||
ctx := context.Background() | ||
|
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
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.
@hannahhoward There's no test for
ErrIncomplete
.