1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-28 05:15:54 +00:00
FrankerFaceZ/socketserver/server/usercount_test.go

69 lines
1.7 KiB
Go
Raw Permalink Normal View History

2015-12-23 21:57:33 -08:00
package server
import (
"net/http/httptest"
"net/url"
"os"
"testing"
"time"
2016-04-28 14:36:59 -07:00
"github.com/satori/go.uuid"
2015-12-23 21:57:33 -08:00
)
func TestUniqueConnections(t *testing.T) {
const TestExpectedCount = 1000
2016-01-17 11:11:21 -08:00
testStart := time.Now().In(CounterLocation)
2015-12-23 21:57:33 -08:00
var server *httptest.Server
var backendExpected = NewTBackendRequestChecker(t,
TExpectedBackendRequest{200, bPathAnnounceStartup, &url.Values{"startup": []string{"1"}}, "", nil},
)
server, _, _ = TSetup(SetupWantSocketServer|SetupWantBackendServer, backendExpected)
defer server.CloseClientConnections()
defer unsubscribeAllClients()
defer backendExpected.Close()
dumpUniqueUsers()
for i := 0; i < TestExpectedCount; i++ {
uuid := uuid.NewV4()
uniqueUserChannel <- uuid
uniqueUserChannel <- uuid
}
TCheckHLLValue(t, TestExpectedCount, readCurrentHLL())
2015-12-23 21:57:33 -08:00
token := <-uniqueCtrWritingToken
2016-01-17 11:11:21 -08:00
uniqueCounter.End = time.Now().In(CounterLocation).Add(-1 * time.Second)
2015-12-23 21:57:33 -08:00
uniqueCtrWritingToken <- token
rolloverCounters_do()
for i := 0; i < TestExpectedCount; i++ {
uuid := uuid.NewV4()
uniqueUserChannel <- uuid
uniqueUserChannel <- uuid
}
TCheckHLLValue(t, TestExpectedCount, readCurrentHLL())
2015-12-23 21:57:33 -08:00
// Check: Merging the two days results in 2000
// note: rolloverCounters_do() wrote out a file, and loadHLL() is reading it back
// TODO need to rewrite some of the test to make this work
2015-12-23 21:57:33 -08:00
var loadDest PeriodUniqueUsers
loadHLL(testStart, &loadDest)
2015-12-23 21:57:33 -08:00
token = <-uniqueCtrWritingToken
loadDest.Counter.Merge(uniqueCounter.Counter)
2015-12-23 21:57:33 -08:00
uniqueCtrWritingToken <- token
TCheckHLLValue(t, TestExpectedCount*2, loadDest.Counter.Count())
}
func TestUniqueUsersCleanup(t *testing.T) {
// Not a test. Removes old files.
os.RemoveAll(uniqCountDir)
}