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