1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-25 23:40:54 +00:00

Add comments, add dumpStackOnCtrlZ() for tests

This commit is contained in:
Kane York 2015-12-23 21:56:56 -08:00
parent 18c1abd3e3
commit 89ff64f52c
9 changed files with 42 additions and 5 deletions

View file

@ -1,10 +1,10 @@
package server
import (
. "gopkg.in/check.v1"
"net/http"
"net/url"
"testing"
"net/http"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
@ -34,6 +34,7 @@ func TestSealRequest(t *testing.T) {
}
type BackendSuite struct{}
var _ = Suite(&BackendSuite{})
func (s *BackendSuite) TestSendRemoteCommand(c *C) {

View file

@ -312,6 +312,7 @@ func C2SEmoticonUses(conn *websocket.Conn, client *ClientInfo, msg ClientMessage
return ResponseSuccess, nil
}
// is_init_func
func aggregateDataSender() {
for {
time.Sleep(5 * time.Minute)
@ -403,6 +404,7 @@ func bunchedRequestFromCM(msg *ClientMessage) bunchedRequest {
return bunchedRequest{Command: msg.Command, Param: msg.origArguments}
}
// is_init_func
func bunchCacheJanitor() {
go func() {
for {

View file

@ -126,6 +126,7 @@ func startJanitors() {
go shutdownHandler()
}
// is_init_func
func shutdownHandler() {
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGUSR1)
@ -139,6 +140,19 @@ func shutdownHandler() {
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.
var SocketUpgrader = websocket.Upgrader{
ReadBufferSize: 1024,

View file

@ -36,6 +36,7 @@ func AddPendingAuthorization(client *ClientInfo, challenge string, callback Auth
})
}
// is_init_func
func authorizationJanitor() {
for {
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")
// is_init_func
func ircConnection() {
c := irc.SimpleClient("justinfan123")

View file

@ -58,11 +58,14 @@ type StatsData struct {
// 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.
// I don't really care.
// Fix anything that -race turns up, but otherwise it's not too much of a problem.
var Statistics = newStatsData()
// CommandCounter is a channel for race-free counting of command usage.
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() {
for cmd := range CommandCounter {
Statistics.CommandsIssuedTotal++
@ -70,6 +73,7 @@ func commandCounter() {
}
}
// StatsDataVersion
const StatsDataVersion = 5
const pageSize = 4096
@ -145,6 +149,7 @@ func updatePeriodicStats() {
var sysMemLastUpdate time.Time
var sysMemUpdateLock sync.Mutex
// updateSysMem reads the system's available RAM.
func updateSysMem() {
if time.Now().Add(-2 * time.Second).After(sysMemLastUpdate) {
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) {
w.Header().Set("Content-Type", "application/json")

View file

@ -145,7 +145,7 @@ func unsubscribeAllClients() {
const ReapingDelay = 1 * time.Minute
// Checks ChatSubscriptionInfo for entries with no subscribers every ReapingDelay.
// Started from SetupServer().
// is_init_func
func pubsubJanitor() {
for {
time.Sleep(ReapingDelay)

View file

@ -11,6 +11,7 @@ import (
"sync"
"syscall"
"testing"
"time"
)
func TestSubscriptionAndPublish(t *testing.T) {
@ -132,6 +133,7 @@ func TestSubscriptionAndPublish(t *testing.T) {
doneWg.Add(1)
readyWg.Wait() // enforce ordering
time.Sleep(2 * time.Millisecond)
readyWg.Add(1)
go func(conn *websocket.Conn) {
TSendMessage(t, conn, 1, HelloCommand, []interface{}{"ffz_0.0-test", uuid.NewV4().String()})

View file

@ -9,6 +9,7 @@ import (
"net/http/httptest"
"net/url"
"os"
"sync"
"testing"
"time"
)
@ -20,7 +21,13 @@ const (
)
const SetupNoServers = 0
var signalCatch sync.Once
func TSetup(flags int, backendChecker *TBackendRequestChecker) (socketserver *httptest.Server, backend *httptest.Server, urls TURLs) {
signalCatch.Do(func() {
go dumpStackOnCtrlZ()
})
DumpBacklogData()
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
&mdash; CatBag by <a href="http://www.twitch.tv/wolsk">Wolsk</a>
</div>
</div>`), 0600)
</div>`), 0644)
conf := &ConfigFile{
ServerID: 20,

View file

@ -6,4 +6,7 @@ package server
// }
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 = 100