Skip to content
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

Fix flaky TestDealFailuresHandlingNonRecoverableErrors #227

Merged
merged 2 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion storagemarket/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestDealFailuresHandlingNonRecoverableErrors(t *testing.T) {
}{
{
dealBuilder: func() *testDeal {
return harness.newDealBuilder(t, 1).withDisconnectingHttpServer().build()
return harness.newDealBuilder(t, 1).withFailingHttpServer().build()
},
errContains: "failed data transfer",
},
Expand Down Expand Up @@ -478,6 +478,7 @@ type ProviderHarness struct {
NormalServer *httptest.Server
BlockingServer *testutil.BlockingHttpTestServer
DisconnectingServer *httptest.Server
FailingServer *httptest.Server
}

type providerConfig struct {
Expand Down Expand Up @@ -564,6 +565,7 @@ func NewHarness(t *testing.T, ctx context.Context, opts ...harnessOpt) *Provider
normalServer := testutil.HttpTestUnstartedFileServer(t, dir)
blockingServer := testutil.NewBlockingHttpTestServer(t, dir)
disconnServer := testutil.HttpTestDisconnectingServer(t, dir, pc.disconnectAfterEvery)
failingServer := testutil.HttpTestUnstartedFailingServer(t)

// create a provider libp2p peer
mn := mocknet.New(ctx)
Expand All @@ -589,6 +591,7 @@ func NewHarness(t *testing.T, ctx context.Context, opts ...harnessOpt) *Provider
NormalServer: normalServer,
BlockingServer: blockingServer,
DisconnectingServer: disconnServer,
FailingServer: failingServer,

MockFullNode: fn,
MockSealingPipelineAPI: sps,
Expand Down Expand Up @@ -675,10 +678,12 @@ func (h *ProviderHarness) Start(t *testing.T, ctx context.Context) {
h.NormalServer.Start()
h.BlockingServer.Start()
h.DisconnectingServer.Start()
h.FailingServer.Start()
require.NoError(t, h.Provider.Start(ctx))
}

func (h *ProviderHarness) Stop() {
h.FailingServer.Close()
h.NormalServer.Close()
h.BlockingServer.Close()
h.DisconnectingServer.Close()
Expand Down Expand Up @@ -851,6 +856,11 @@ func (tbuilder *testDealBuilder) withAllMinerCallsBlocking() *testDealBuilder {
return tbuilder
}

func (tbuilder *testDealBuilder) withFailingHttpServer() *testDealBuilder {
tbuilder.setTransferParams(tbuilder.td.ph.FailingServer.URL)
return tbuilder
}

func (tbuilder *testDealBuilder) withBlockingHttpServer() *testDealBuilder {
tbuilder.ph.BlockingServer.AddFile(tbuilder.td.carv2FileName)
tbuilder.setTransferParams(tbuilder.td.ph.BlockingServer.URL)
Expand Down
7 changes: 7 additions & 0 deletions testutil/httptestfileservers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func HttpTestFileServer(t *testing.T, dir string) (*httptest.Server, error) {
return svr, nil
}

func HttpTestUnstartedFailingServer(t *testing.T) *httptest.Server {
svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(401)
}))
return svr
}

// HttpTestUnstartedFileServer returns a http server that serves files from the given directory
func HttpTestUnstartedFileServer(t *testing.T, dir string) *httptest.Server {
handler := http.FileServer(http.Dir(dir))
Expand Down