mirror of
https://github.com/p1neappleXpress/OpenFlux.git
synced 2026-10-02 05:04:39 +08:00
Renames the Go module path from openflux to github.com/p1neappleXpress/OpenFlux and updates every internal import (root module and mobile/), so the packages can be fetched and imported by other Go projects. Regenerated on main after #132, #122 and #125 (the same mechanical rename, imports sorted by gofmt). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/p1neappleXpress/OpenFlux/transport"
|
|
"github.com/p1neappleXpress/OpenFlux/transport/ipc"
|
|
)
|
|
|
|
type fixedStats struct{ in, out uint64 }
|
|
|
|
func (f fixedStats) IsConnected() bool { return true }
|
|
func (f fixedStats) Stats() transport.TransportStats {
|
|
return transport.TransportStats{BytesReceived: f.in, BytesSent: f.out}
|
|
}
|
|
|
|
// A classic carrier without a Session reports its traffic too: the app's
|
|
// speed counters read it.
|
|
func TestIPCStatusWithoutSession(t *testing.T) {
|
|
dir, err := os.MkdirTemp("", "ofipc")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(dir)
|
|
path := filepath.Join(dir, "s.sock")
|
|
srv := ipc.NewServer(path, &coreIPCHandler{})
|
|
if err := srv.Listen(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer srv.Close()
|
|
go ipcStatusLoop(srv, fixedStats{in: 1500, out: 700}, nil)
|
|
|
|
c, err := ipc.Dial(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer c.Close()
|
|
got := make(chan ipc.StatusPayload, 1)
|
|
c.SetHandler(func(typ ipc.MsgType, body []byte) {
|
|
if typ != ipc.MsgStatus {
|
|
return
|
|
}
|
|
var p ipc.StatusPayload
|
|
if json.Unmarshal(body, &p) == nil {
|
|
select {
|
|
case got <- p:
|
|
default:
|
|
}
|
|
}
|
|
})
|
|
select {
|
|
case p := <-got:
|
|
if !p.Connected || p.BytesIn != 1500 || p.BytesOut != 700 || p.Active != "" {
|
|
t.Fatalf("status = %+v", p)
|
|
}
|
|
case <-time.After(3 * time.Second):
|
|
t.Fatal("no status")
|
|
}
|
|
}
|