mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-07-28 13:38:30 +00:00
backlog data types, test stuff
This commit is contained in:
parent
812c6f2557
commit
69676bf287
2 changed files with 58 additions and 37 deletions
|
@ -39,7 +39,6 @@ var ServerInitiatedCommands = map[string]PushCommandCacheInfo{
|
|||
"chatters": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
||||
"viewers": {CacheTypeLastOnly, MsgTargetTypeWatching}, // cachelast:watching
|
||||
}
|
||||
var _ = ServerInitiatedCommands
|
||||
|
||||
type BacklogCacheType int
|
||||
|
||||
|
@ -50,6 +49,7 @@ const (
|
|||
CacheTypeNever
|
||||
// Save the last 24 hours of this message.
|
||||
// If a client indicates that it has reconnected, replay the messages sent after the disconnect.
|
||||
// Do not replay if the client indicates that this is a firstload.
|
||||
CacheTypeTimestamps
|
||||
// Save only the last copy of this message, and always send it when the backlog is requested.
|
||||
CacheTypeLastOnly
|
||||
|
@ -83,13 +83,29 @@ var ErrorUnrecognizedCacheType = errors.New("Invalid value for cachetype")
|
|||
// Returned by MessageTargetType.UnmarshalJSON()
|
||||
var ErrorUnrecognizedTargetType = errors.New("Invalid value for message target")
|
||||
|
||||
type PersistentCachedData struct {
|
||||
type PersistentCachedMessage struct {
|
||||
Timestamp time.Time
|
||||
Channel string
|
||||
Watching bool
|
||||
Data string
|
||||
}
|
||||
|
||||
type TimestampedGlobalMessage struct {
|
||||
Timestamp time.Time
|
||||
Data string
|
||||
}
|
||||
|
||||
type TimestampedMultichatMessage struct {
|
||||
Timestamp time.Time
|
||||
Channels string
|
||||
Data string
|
||||
}
|
||||
|
||||
type LastSavedMessage struct {
|
||||
Timestamp time.Time
|
||||
Data string
|
||||
}
|
||||
|
||||
// map command -> channel -> data
|
||||
var CachedDataLast map[Command]map[string]string
|
||||
|
||||
|
|
|
@ -59,12 +59,38 @@ type TURLs struct {
|
|||
PubMsg string
|
||||
}
|
||||
|
||||
func TGetUrls(testserver httptest.Server) TURLs {
|
||||
func TGetUrls(testserver *httptest.Server) TURLs {
|
||||
addr := testserver.Listener.Addr().String()
|
||||
return TURLs{
|
||||
Websocket: fmt.Sprintf("ws://%s/", addr),
|
||||
Origin: fmt.Sprintf("http://%s"),
|
||||
PubMsg: fmt.Sprintf("http://%s/pub_msg"),
|
||||
Origin: fmt.Sprintf("http://%s", addr),
|
||||
PubMsg: fmt.Sprintf("http://%s/pub_msg", addr),
|
||||
}
|
||||
}
|
||||
|
||||
const TNaclKeysLocation = "/tmp/test_naclkeys.json"
|
||||
|
||||
func TSetup(testserver **httptest.Server, urls *TURLs) {
|
||||
if backendSharedKey[0] == 0 {
|
||||
GenerateKeys(TNaclKeysLocation, "2", "+ZMqOmxhaVrCV5c0OMZ09QoSGcJHuqQtJrwzRD+JOjE=")
|
||||
}
|
||||
DumpCache()
|
||||
|
||||
if testserver != nil {
|
||||
conf := &Config{
|
||||
UseSSL: false,
|
||||
NaclKeysFile: TNaclKeysLocation,
|
||||
SocketOrigin: "localhost:2002",
|
||||
}
|
||||
serveMux := http.NewServeMux()
|
||||
SetupServerAndHandle(conf, nil, serveMux)
|
||||
|
||||
tserv := httptest.NewUnstartedServer(serveMux)
|
||||
*testserver = tserv
|
||||
tserv.Start()
|
||||
if urls != nil {
|
||||
*urls = TGetUrls(tserv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,20 +102,10 @@ func TestSubscriptionAndPublish(t *testing.T) {
|
|||
const TestCommand = "testdata"
|
||||
const TestData = "123456789"
|
||||
|
||||
GenerateKeys("/tmp/test_naclkeys.json", "2", "+ZMqOmxhaVrCV5c0OMZ09QoSGcJHuqQtJrwzRD+JOjE=")
|
||||
DumpCache()
|
||||
conf := &Config{
|
||||
UseSSL: false,
|
||||
NaclKeysFile: "/tmp/test_naclkeys.json",
|
||||
SocketOrigin: "localhost:2002",
|
||||
}
|
||||
serveMux := http.NewServeMux()
|
||||
SetupServerAndHandle(conf, nil, serveMux)
|
||||
|
||||
server := httptest.NewUnstartedServer(serveMux)
|
||||
server.Start()
|
||||
|
||||
urls := TGetUrls(server)
|
||||
var server *httptest.Server
|
||||
var urls TURLs
|
||||
TSetup(&server, &urls)
|
||||
defer unsubscribeAllClients()
|
||||
|
||||
conn, err := websocket.Dial(urls.Websocket, "", urls.Origin)
|
||||
if err != nil {
|
||||
|
@ -150,7 +166,7 @@ func TestSubscriptionAndPublish(t *testing.T) {
|
|||
server.Close()
|
||||
}
|
||||
|
||||
func BenchmarkThousandUserSubscription(b *testing.B) {
|
||||
func BenchmarkUserSubscriptionSinglePublish(b *testing.B) {
|
||||
var doneWg sync.WaitGroup
|
||||
var readyWg sync.WaitGroup
|
||||
|
||||
|
@ -158,21 +174,6 @@ func BenchmarkThousandUserSubscription(b *testing.B) {
|
|||
const TestCommand = "testdata"
|
||||
const TestData = "123456789"
|
||||
|
||||
GenerateKeys("/tmp/test_naclkeys.json", "2", "+ZMqOmxhaVrCV5c0OMZ09QoSGcJHuqQtJrwzRD+JOjE=")
|
||||
DumpCache()
|
||||
conf := &Config{
|
||||
UseSSL: false,
|
||||
NaclKeysFile: "/tmp/test_naclkeys.json",
|
||||
SocketOrigin: "localhost:2002",
|
||||
}
|
||||
serveMux := http.NewServeMux()
|
||||
SetupServerAndHandle(conf, nil, serveMux)
|
||||
|
||||
server := httptest.NewUnstartedServer(serveMux)
|
||||
server.Start()
|
||||
|
||||
urls := TGetUrls(server)
|
||||
|
||||
message := ClientMessage{MessageID: -1, Command: "testdata", Arguments: TestData}
|
||||
|
||||
fmt.Println()
|
||||
|
@ -190,6 +191,11 @@ func BenchmarkThousandUserSubscription(b *testing.B) {
|
|||
|
||||
syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit)
|
||||
|
||||
var server *httptest.Server
|
||||
var urls TURLs
|
||||
TSetup(&server, &urls)
|
||||
defer unsubscribeAllClients()
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
conn, err := websocket.Dial(urls.Websocket, "", urls.Origin)
|
||||
|
@ -206,7 +212,6 @@ func BenchmarkThousandUserSubscription(b *testing.B) {
|
|||
TReceiveExpectedMessage(b, conn, 1, SuccessCommand, IgnoreReceivedArguments)
|
||||
TReceiveExpectedMessage(b, conn, 2, SuccessCommand, nil)
|
||||
|
||||
fmt.Println(i, " ready")
|
||||
readyWg.Done()
|
||||
|
||||
TReceiveExpectedMessage(b, conn, -1, TestCommand, TestData)
|
||||
|
@ -225,9 +230,9 @@ func BenchmarkThousandUserSubscription(b *testing.B) {
|
|||
panic("halting test instead of waiting")
|
||||
}
|
||||
doneWg.Wait()
|
||||
fmt.Println("...done.")
|
||||
|
||||
b.StopTimer()
|
||||
server.Close()
|
||||
unsubscribeAllClients()
|
||||
server.CloseClientConnections()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue