mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-11 00:20:54 +00:00
Add comments, add dumpStackOnCtrlZ() for tests
This commit is contained in:
parent
18c1abd3e3
commit
89ff64f52c
9 changed files with 42 additions and 5 deletions
|
@ -1,10 +1,10 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
"net/http"
|
|
||||||
. "gopkg.in/check.v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) { TestingT(t) }
|
||||||
|
@ -34,6 +34,7 @@ func TestSealRequest(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type BackendSuite struct{}
|
type BackendSuite struct{}
|
||||||
|
|
||||||
var _ = Suite(&BackendSuite{})
|
var _ = Suite(&BackendSuite{})
|
||||||
|
|
||||||
func (s *BackendSuite) TestSendRemoteCommand(c *C) {
|
func (s *BackendSuite) TestSendRemoteCommand(c *C) {
|
||||||
|
|
|
@ -312,6 +312,7 @@ func C2SEmoticonUses(conn *websocket.Conn, client *ClientInfo, msg ClientMessage
|
||||||
return ResponseSuccess, nil
|
return ResponseSuccess, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is_init_func
|
||||||
func aggregateDataSender() {
|
func aggregateDataSender() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Minute)
|
time.Sleep(5 * time.Minute)
|
||||||
|
@ -403,6 +404,7 @@ func bunchedRequestFromCM(msg *ClientMessage) bunchedRequest {
|
||||||
return bunchedRequest{Command: msg.Command, Param: msg.origArguments}
|
return bunchedRequest{Command: msg.Command, Param: msg.origArguments}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is_init_func
|
||||||
func bunchCacheJanitor() {
|
func bunchCacheJanitor() {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -126,6 +126,7 @@ func startJanitors() {
|
||||||
go shutdownHandler()
|
go shutdownHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is_init_func
|
||||||
func shutdownHandler() {
|
func shutdownHandler() {
|
||||||
ch := make(chan os.Signal)
|
ch := make(chan os.Signal)
|
||||||
signal.Notify(ch, syscall.SIGUSR1)
|
signal.Notify(ch, syscall.SIGUSR1)
|
||||||
|
@ -139,6 +140,19 @@ func shutdownHandler() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is_init_func +test
|
||||||
|
func dumpStackOnCtrlZ() {
|
||||||
|
ch := make(chan os.Signal)
|
||||||
|
signal.Notify(ch, syscall.SIGTSTP)
|
||||||
|
for _ = range ch {
|
||||||
|
fmt.Println("Got ^Z")
|
||||||
|
|
||||||
|
buf := make([]byte, 10000)
|
||||||
|
byteCnt := runtime.Stack(buf, true)
|
||||||
|
fmt.Println(string(buf[:byteCnt]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SocketUpgrader is the websocket.Upgrader currently in use.
|
// SocketUpgrader is the websocket.Upgrader currently in use.
|
||||||
var SocketUpgrader = websocket.Upgrader{
|
var SocketUpgrader = websocket.Upgrader{
|
||||||
ReadBufferSize: 1024,
|
ReadBufferSize: 1024,
|
||||||
|
|
|
@ -36,6 +36,7 @@ func AddPendingAuthorization(client *ClientInfo, challenge string, callback Auth
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is_init_func
|
||||||
func authorizationJanitor() {
|
func authorizationJanitor() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Minute)
|
time.Sleep(5 * time.Minute)
|
||||||
|
@ -90,6 +91,7 @@ const DEBUG = "DEBUG"
|
||||||
|
|
||||||
var errChallengeNotFound = errors.New("did not find a challenge solved by that message")
|
var errChallengeNotFound = errors.New("did not find a challenge solved by that message")
|
||||||
|
|
||||||
|
// is_init_func
|
||||||
func ircConnection() {
|
func ircConnection() {
|
||||||
|
|
||||||
c := irc.SimpleClient("justinfan123")
|
c := irc.SimpleClient("justinfan123")
|
||||||
|
|
|
@ -58,11 +58,14 @@ type StatsData struct {
|
||||||
// Its structure should be versioned as it is exposed via JSON.
|
// Its structure should be versioned as it is exposed via JSON.
|
||||||
//
|
//
|
||||||
// Note as to threaded access - this is soft/fun data and not critical to data integrity.
|
// Note as to threaded access - this is soft/fun data and not critical to data integrity.
|
||||||
// I don't really care.
|
// Fix anything that -race turns up, but otherwise it's not too much of a problem.
|
||||||
var Statistics = newStatsData()
|
var Statistics = newStatsData()
|
||||||
|
|
||||||
|
// CommandCounter is a channel for race-free counting of command usage.
|
||||||
var CommandCounter = make(chan Command, 10)
|
var CommandCounter = make(chan Command, 10)
|
||||||
|
|
||||||
|
// commandCounter receives from the CommandCounter channel and uses the value to increment the values in Statistics.
|
||||||
|
// is_init_func
|
||||||
func commandCounter() {
|
func commandCounter() {
|
||||||
for cmd := range CommandCounter {
|
for cmd := range CommandCounter {
|
||||||
Statistics.CommandsIssuedTotal++
|
Statistics.CommandsIssuedTotal++
|
||||||
|
@ -70,6 +73,7 @@ func commandCounter() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatsDataVersion
|
||||||
const StatsDataVersion = 5
|
const StatsDataVersion = 5
|
||||||
const pageSize = 4096
|
const pageSize = 4096
|
||||||
|
|
||||||
|
@ -145,6 +149,7 @@ func updatePeriodicStats() {
|
||||||
var sysMemLastUpdate time.Time
|
var sysMemLastUpdate time.Time
|
||||||
var sysMemUpdateLock sync.Mutex
|
var sysMemUpdateLock sync.Mutex
|
||||||
|
|
||||||
|
// updateSysMem reads the system's available RAM.
|
||||||
func updateSysMem() {
|
func updateSysMem() {
|
||||||
if time.Now().Add(-2 * time.Second).After(sysMemLastUpdate) {
|
if time.Now().Add(-2 * time.Second).After(sysMemLastUpdate) {
|
||||||
sysMemUpdateLock.Lock()
|
sysMemUpdateLock.Lock()
|
||||||
|
@ -163,6 +168,7 @@ func updateSysMem() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTPShowStatistics handles the /stats endpoint. It writes out the Statistics object as indented JSON.
|
||||||
func HTTPShowStatistics(w http.ResponseWriter, r *http.Request) {
|
func HTTPShowStatistics(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ func unsubscribeAllClients() {
|
||||||
const ReapingDelay = 1 * time.Minute
|
const ReapingDelay = 1 * time.Minute
|
||||||
|
|
||||||
// Checks ChatSubscriptionInfo for entries with no subscribers every ReapingDelay.
|
// Checks ChatSubscriptionInfo for entries with no subscribers every ReapingDelay.
|
||||||
// Started from SetupServer().
|
// is_init_func
|
||||||
func pubsubJanitor() {
|
func pubsubJanitor() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(ReapingDelay)
|
time.Sleep(ReapingDelay)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSubscriptionAndPublish(t *testing.T) {
|
func TestSubscriptionAndPublish(t *testing.T) {
|
||||||
|
@ -132,6 +133,7 @@ func TestSubscriptionAndPublish(t *testing.T) {
|
||||||
|
|
||||||
doneWg.Add(1)
|
doneWg.Add(1)
|
||||||
readyWg.Wait() // enforce ordering
|
readyWg.Wait() // enforce ordering
|
||||||
|
time.Sleep(2 * time.Millisecond)
|
||||||
readyWg.Add(1)
|
readyWg.Add(1)
|
||||||
go func(conn *websocket.Conn) {
|
go func(conn *websocket.Conn) {
|
||||||
TSendMessage(t, conn, 1, HelloCommand, []interface{}{"ffz_0.0-test", uuid.NewV4().String()})
|
TSendMessage(t, conn, 1, HelloCommand, []interface{}{"ffz_0.0-test", uuid.NewV4().String()})
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -20,7 +21,13 @@ const (
|
||||||
)
|
)
|
||||||
const SetupNoServers = 0
|
const SetupNoServers = 0
|
||||||
|
|
||||||
|
var signalCatch sync.Once
|
||||||
|
|
||||||
func TSetup(flags int, backendChecker *TBackendRequestChecker) (socketserver *httptest.Server, backend *httptest.Server, urls TURLs) {
|
func TSetup(flags int, backendChecker *TBackendRequestChecker) (socketserver *httptest.Server, backend *httptest.Server, urls TURLs) {
|
||||||
|
signalCatch.Do(func() {
|
||||||
|
go dumpStackOnCtrlZ()
|
||||||
|
})
|
||||||
|
|
||||||
DumpBacklogData()
|
DumpBacklogData()
|
||||||
|
|
||||||
ioutil.WriteFile("index.html", []byte(`
|
ioutil.WriteFile("index.html", []byte(`
|
||||||
|
@ -36,7 +43,7 @@ func TSetup(flags int, backendChecker *TBackendRequestChecker) (socketserver *ht
|
||||||
A <a href="http://www.frankerfacez.com/">FrankerFaceZ</a> Service
|
A <a href="http://www.frankerfacez.com/">FrankerFaceZ</a> Service
|
||||||
— CatBag by <a href="http://www.twitch.tv/wolsk">Wolsk</a>
|
— CatBag by <a href="http://www.twitch.tv/wolsk">Wolsk</a>
|
||||||
</div>
|
</div>
|
||||||
</div>`), 0600)
|
</div>`), 0644)
|
||||||
|
|
||||||
conf := &ConfigFile{
|
conf := &ConfigFile{
|
||||||
ServerID: 20,
|
ServerID: 20,
|
||||||
|
|
|
@ -6,4 +6,7 @@ package server
|
||||||
// }
|
// }
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
// note: this seems to add 0.1s to compile time on my machine
|
||||||
var ticksPerSecond = int(C.get_ticks_per_second())
|
var ticksPerSecond = int(C.get_ticks_per_second())
|
||||||
|
|
||||||
|
//var ticksPerSecond = 100
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue