Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Use buffered channels, add test for invalid hash

Cette révision appartient à :
ElegantMonkey 2017-05-13 19:35:35 -03:00
Parent fb677d4d9d
révision 4d69ee4eaa
3 fichiers modifiés avec 48 ajouts et 3 suppressions

Voir le fichier

@ -29,11 +29,11 @@ func New(fetcherConfig *config.FilesizeFetcherConfig) (fetcher *FilesizeFetcher,
client, err := torrent.NewClient(nil)
fetcher = &FilesizeFetcher{
torrentClient: client,
results: make(chan Result),
results: make(chan Result, fetcherConfig.QueueSize),
queueSize: fetcherConfig.QueueSize,
timeout: fetcherConfig.Timeout,
maxDays: fetcherConfig.MaxDays,
done: make(chan int),
done: make(chan int, 1),
failedOperations: make(map[uint]struct{}),
wakeUp: time.NewTicker(time.Second * time.Duration(fetcherConfig.WakeUpInterval)),
}

Voir le fichier

@ -26,7 +26,7 @@ func NewFetchOperation(fetcher *FilesizeFetcher, dbEntry model.Torrent) (op *Fet
op = &FetchOperation{
fetcher: fetcher,
torrent: dbEntry,
done: make(chan int),
done: make(chan int, 1),
}
return
}

Voir le fichier

@ -0,0 +1,45 @@
package filesizeFetcher;
import (
"testing"
"github.com/anacrolix/torrent"
"github.com/ewhal/nyaa/model"
)
func TestInvalidHash(t *testing.T) {
client, err := torrent.NewClient(nil)
if err != nil {
t.Skipf("Failed to create client, with err %v. Skipping.", err)
}
fetcher := &FilesizeFetcher{
timeout: 5,
torrentClient: client,
results: make(chan Result, 1),
}
dbEntry := model.Torrent{
Hash: "INVALID",
Name: "Invalid",
}
op := NewFetchOperation(fetcher, dbEntry)
fetcher.wg.Add(1)
op.Start(fetcher.results)
var res Result
select {
case res = <-fetcher.results:
break
default:
t.Fatal("No result in channel, should have one")
}
if res.err == nil {
t.Fatal("Got no error, should have got invalid magnet")
}
t.Logf("Got error %s, shouldn't be timeout", res.err)
}