Cleanup Redis keys after tests and benchmarks

This commit is contained in:
cpb8010 2013-09-28 09:09:03 -04:00
parent b7dc80e4a3
commit 11c0c3cb3c
2 changed files with 86 additions and 2 deletions

View file

@ -2,7 +2,6 @@
// Use of this source code is governed by the BSD 2-Clause license, // Use of this source code is governed by the BSD 2-Clause license,
// which can be found in the LICENSE file. // which can be found in the LICENSE file.
// Benchmarks two different redis schemeas
package redis package redis
import ( import (
@ -29,6 +28,10 @@ func BenchmarkSuccessfulFindUser(b *testing.B) {
b.Error("found user mismatch", *foundUser, testUser) b.Error("found user mismatch", *foundUser, testUser)
} }
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveUser(testUser))
b.StartTimer()
} }
func BenchmarkFailedFindUser(b *testing.B) { func BenchmarkFailedFindUser(b *testing.B) {
@ -66,6 +69,10 @@ func BenchmarkSuccessfulFindTorrent(b *testing.B) {
b.Error("found torrent mismatch", foundTorrent, testTorrent) b.Error("found torrent mismatch", foundTorrent, testTorrent)
} }
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveTorrent(testTorrent))
b.StartTimer()
} }
func BenchmarkFailFindTorrent(b *testing.B) { func BenchmarkFailFindTorrent(b *testing.B) {
@ -97,6 +104,10 @@ func BenchmarkSuccessfulClientWhitelisted(b *testing.B) {
b.Error("peerID not found", testPeerID) b.Error("peerID not found", testPeerID)
} }
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.UnWhitelistClient(testPeerID))
b.StartTimer()
} }
func BenchmarkFailClientWhitelisted(b *testing.B) { func BenchmarkFailClientWhitelisted(b *testing.B) {
@ -126,6 +137,11 @@ func BenchmarkRecordSnatch(b *testing.B) {
for bCount := 0; bCount < b.N; bCount++ { for bCount := 0; bCount < b.N; bCount++ {
panicOnErr(tx.RecordSnatch(testUser, testTorrent)) panicOnErr(tx.RecordSnatch(testUser, testTorrent))
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveTorrent(testTorrent))
panicOnErr(tx.RemoveUser(testUser))
b.StartTimer()
} }
func BenchmarkMarkActive(b *testing.B) { func BenchmarkMarkActive(b *testing.B) {
@ -139,6 +155,10 @@ func BenchmarkMarkActive(b *testing.B) {
for bCount := 0; bCount < b.N; bCount++ { for bCount := 0; bCount < b.N; bCount++ {
panicOnErr(tx.MarkActive(testTorrent)) panicOnErr(tx.MarkActive(testTorrent))
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveTorrent(testTorrent))
b.StartTimer()
} }
func BenchmarkAddSeeder(b *testing.B) { func BenchmarkAddSeeder(b *testing.B) {
@ -155,6 +175,10 @@ func BenchmarkAddSeeder(b *testing.B) {
panicOnErr(tx.AddSeeder(testTorrent, testSeeder)) panicOnErr(tx.AddSeeder(testTorrent, testSeeder))
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveTorrent(testTorrent))
b.StartTimer()
} }
func BenchmarkRemoveSeeder(b *testing.B) { func BenchmarkRemoveSeeder(b *testing.B) {
@ -172,6 +196,10 @@ func BenchmarkRemoveSeeder(b *testing.B) {
panicOnErr(tx.RemoveSeeder(testTorrent, testSeeder)) panicOnErr(tx.RemoveSeeder(testTorrent, testSeeder))
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveTorrent(testTorrent))
b.StartTimer()
} }
func BenchmarkSetSeeder(b *testing.B) { func BenchmarkSetSeeder(b *testing.B) {
@ -191,6 +219,10 @@ func BenchmarkSetSeeder(b *testing.B) {
tx.SetSeeder(testTorrent, testSeeder) tx.SetSeeder(testTorrent, testSeeder)
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveTorrent(testTorrent))
b.StartTimer()
} }
func BenchmarkIncrementSlots(b *testing.B) { func BenchmarkIncrementSlots(b *testing.B) {
@ -203,6 +235,10 @@ func BenchmarkIncrementSlots(b *testing.B) {
for bCount := 0; bCount < b.N; bCount++ { for bCount := 0; bCount < b.N; bCount++ {
panicOnErr(tx.IncrementSlots(testUser)) panicOnErr(tx.IncrementSlots(testUser))
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveUser(testUser))
b.StartTimer()
} }
func BenchmarkLeecherFinished(b *testing.B) { func BenchmarkLeecherFinished(b *testing.B) {
@ -221,6 +257,10 @@ func BenchmarkLeecherFinished(b *testing.B) {
panicOnErr(tx.LeecherFinished(testTorrent, testLeecher)) panicOnErr(tx.LeecherFinished(testTorrent, testLeecher))
} }
// Cleanup
b.StopTimer()
panicOnErr(tx.RemoveTorrent(testTorrent))
b.StartTimer()
} }
// This is a comparision to the Leecher finished function // This is a comparision to the Leecher finished function
@ -241,5 +281,8 @@ func BenchmarkRemoveLeecherAddSeeder(b *testing.B) {
panicOnErr(tx.RemoveLeecher(testTorrent, testLeecher)) panicOnErr(tx.RemoveLeecher(testTorrent, testLeecher))
panicOnErr(tx.AddSeeder(testTorrent, testLeecher)) panicOnErr(tx.AddSeeder(testTorrent, testLeecher))
} }
// Cleanup
b.StopTimer()
tx.RemoveTorrent(testTorrent)
b.StartTimer()
} }

View file

@ -43,6 +43,8 @@ func TestFindUserSuccess(t *testing.T) {
if *foundUser != *testUser { if *foundUser != *testUser {
t.Error("found user mismatch", *foundUser, testUser) t.Error("found user mismatch", *foundUser, testUser)
} }
// Cleanup
panicOnErr(tx.RemoveUser(testUser))
} }
func TestFindUserFail(t *testing.T) { func TestFindUserFail(t *testing.T) {
@ -83,6 +85,8 @@ func TestFindTorrentSuccess(t *testing.T) {
if !reflect.DeepEqual(foundTorrent, testTorrent) { if !reflect.DeepEqual(foundTorrent, testTorrent) {
t.Error("found torrent mismatch", foundTorrent, testTorrent) t.Error("found torrent mismatch", foundTorrent, testTorrent)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestFindTorrentFail(t *testing.T) { func TestFindTorrentFail(t *testing.T) {
@ -107,6 +111,8 @@ func TestRemoveTorrent(t *testing.T) {
if found { if found {
t.Error("removed torrent found", foundTorrent) t.Error("removed torrent found", foundTorrent)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestClientWhitelistSuccess(t *testing.T) { func TestClientWhitelistSuccess(t *testing.T) {
@ -119,6 +125,8 @@ func TestClientWhitelistSuccess(t *testing.T) {
if !found { if !found {
t.Error("peerID not found", testPeerID) t.Error("peerID not found", testPeerID)
} }
// Cleanup
panicOnErr(tx.UnWhitelistClient(testPeerID))
} }
func TestClientWhitelistFail(t *testing.T) { func TestClientWhitelistFail(t *testing.T) {
@ -161,6 +169,9 @@ func TestRecordSnatch(t *testing.T) {
if foundTorrent.Snatches != torrentSnatches+1 { if foundTorrent.Snatches != torrentSnatches+1 {
t.Error("snatch not recorded to cached torrent") t.Error("snatch not recorded to cached torrent")
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
panicOnErr(tx.RemoveUser(testUser))
} }
func TestMarkActive(t *testing.T) { func TestMarkActive(t *testing.T) {
@ -179,6 +190,8 @@ func TestMarkActive(t *testing.T) {
if testTorrent.Active != true { if testTorrent.Active != true {
t.Error("cached torrent not activated") t.Error("cached torrent not activated")
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestClientWhitelistRemove(t *testing.T) { func TestClientWhitelistRemove(t *testing.T) {
@ -211,6 +224,8 @@ func TestAddSeeder(t *testing.T) {
if found && foundSeeder != *testSeeder { if found && foundSeeder != *testSeeder {
t.Error("seeder not added to local", testSeeder) t.Error("seeder not added to local", testSeeder)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestAddLeecher(t *testing.T) { func TestAddLeecher(t *testing.T) {
@ -230,6 +245,8 @@ func TestAddLeecher(t *testing.T) {
if found && foundLeecher != *testLeecher { if found && foundLeecher != *testLeecher {
t.Error("leecher not added to local", testLeecher) t.Error("leecher not added to local", testLeecher)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestRemoveSeeder(t *testing.T) { func TestRemoveSeeder(t *testing.T) {
@ -251,6 +268,8 @@ func TestRemoveSeeder(t *testing.T) {
if found || foundSeeder == *testSeeder { if found || foundSeeder == *testSeeder {
t.Error("seeder not removed from cache", foundSeeder, *testSeeder) t.Error("seeder not removed from cache", foundSeeder, *testSeeder)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestRemoveLeecher(t *testing.T) { func TestRemoveLeecher(t *testing.T) {
@ -271,6 +290,8 @@ func TestRemoveLeecher(t *testing.T) {
if found || foundLeecher == *testLeecher { if found || foundLeecher == *testLeecher {
t.Error("leecher not removed from local", foundLeecher, *testLeecher) t.Error("leecher not removed from local", foundLeecher, *testLeecher)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestSetSeeder(t *testing.T) { func TestSetSeeder(t *testing.T) {
@ -295,6 +316,8 @@ func TestSetSeeder(t *testing.T) {
if foundSeeder != *testSeeder { if foundSeeder != *testSeeder {
t.Error("seeder not updated in local", foundSeeder, *testSeeder) t.Error("seeder not updated in local", foundSeeder, *testSeeder)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestSetLeecher(t *testing.T) { func TestSetLeecher(t *testing.T) {
@ -318,6 +341,8 @@ func TestSetLeecher(t *testing.T) {
if foundLeecher != *testLeecher { if foundLeecher != *testLeecher {
t.Error("leecher not updated in local", testLeecher) t.Error("leecher not updated in local", testLeecher)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestIncrementSlots(t *testing.T) { func TestIncrementSlots(t *testing.T) {
@ -336,6 +361,8 @@ func TestIncrementSlots(t *testing.T) {
if testUser.Slots != numSlots+1 { if testUser.Slots != numSlots+1 {
t.Error("local slots not incremented") t.Error("local slots not incremented")
} }
// Cleanup
panicOnErr(tx.RemoveUser(testUser))
} }
func TestDecrementSlots(t *testing.T) { func TestDecrementSlots(t *testing.T) {
@ -354,6 +381,8 @@ func TestDecrementSlots(t *testing.T) {
if testUser.Slots != numSlots-1 { if testUser.Slots != numSlots-1 {
t.Error("local slots not incremented") t.Error("local slots not incremented")
} }
// Cleanup
panicOnErr(tx.RemoveUser(testUser))
} }
func TestLeecherFinished(t *testing.T) { func TestLeecherFinished(t *testing.T) {
@ -384,6 +413,8 @@ func TestLeecherFinished(t *testing.T) {
if foundSeeder == *testLeecher { if foundSeeder == *testLeecher {
t.Error("leecher not removed from local", testLeecher) t.Error("leecher not removed from local", testLeecher)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
// Add, update, verify remove // Add, update, verify remove
@ -408,6 +439,8 @@ func TestUpdatePeer(t *testing.T) {
if seeder, exists := testTorrent.Seeders[models.PeerMapKey(testSeeder)]; exists { if seeder, exists := testTorrent.Seeders[models.PeerMapKey(testSeeder)]; exists {
t.Error("seeder not removed from local", seeder) t.Error("seeder not removed from local", seeder)
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestParallelFindUser(t *testing.T) { func TestParallelFindUser(t *testing.T) {
@ -435,6 +468,8 @@ func TestParallelFindUser(t *testing.T) {
t.Error("found user mismatch", *foundUser, testUserSuccess) t.Error("found user mismatch", *foundUser, testUserSuccess)
} }
} }
// Cleanup
panicOnErr(tx.RemoveUser(testUserSuccess))
} }
func TestParallelFindTorrent(t *testing.T) { func TestParallelFindTorrent(t *testing.T) {
@ -462,6 +497,8 @@ func TestParallelFindTorrent(t *testing.T) {
t.Error("torrent found", foundTorrent) t.Error("torrent found", foundTorrent)
} }
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrentSuccess))
} }
func TestParallelSetSeeder(t *testing.T) { func TestParallelSetSeeder(t *testing.T) {
@ -492,6 +529,8 @@ func TestParallelSetSeeder(t *testing.T) {
t.Error("seeder not updated in local", foundSeeder, *testSeeder) t.Error("seeder not updated in local", foundSeeder, *testSeeder)
} }
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }
func TestParallelAddLeecher(t *testing.T) { func TestParallelAddLeecher(t *testing.T) {
@ -519,4 +558,6 @@ func TestParallelAddLeecher(t *testing.T) {
t.Error("leecher not added to local", testLeecher) t.Error("leecher not added to local", testLeecher)
} }
} }
// Cleanup
panicOnErr(tx.RemoveTorrent(testTorrent))
} }