-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #954 from SiaFoundation/chris/uploader-downloader-…
…stopped Fail upload/download request if uploader/downloader was already stopped
- Loading branch information
Showing
4 changed files
with
100 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package worker | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestDownloaderStopped(t *testing.T) { | ||
w := newMockWorker() | ||
h := w.addHost() | ||
w.dl.refreshDownloaders(w.contracts()) | ||
|
||
dl := w.dl.downloaders[h.PublicKey()] | ||
dl.Stop() | ||
|
||
req := sectorDownloadReq{ | ||
resps: §orResponses{ | ||
c: make(chan struct{}), | ||
}, | ||
} | ||
dl.enqueue(&req) | ||
|
||
select { | ||
case <-req.resps.c: | ||
if err := req.resps.responses[0].err; !errors.Is(err, errDownloaderStopped) { | ||
t.Fatal("unexpected error response", err) | ||
} | ||
case <-time.After(10 * time.Second): | ||
t.Fatal("no response") | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package worker | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestUploaderStopped(t *testing.T) { | ||
w := newMockWorker() | ||
w.addHost() | ||
w.ul.refreshUploaders(w.contracts(), 1) | ||
|
||
ul := w.ul.uploaders[0] | ||
ul.Stop(errors.New("test")) | ||
|
||
req := sectorUploadReq{ | ||
responseChan: make(chan sectorUploadResp), | ||
sector: §orUpload{ctx: context.Background()}, | ||
} | ||
ul.enqueue(&req) | ||
|
||
select { | ||
case res := <-req.responseChan: | ||
if !errors.Is(res.err, errUploaderStopped) { | ||
t.Fatal("expected error response") | ||
} | ||
case <-time.After(10 * time.Second): | ||
t.Fatal("no response") | ||
} | ||
} |