mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-08-04 07:07:53 +00:00
Some checks are pending
Build and Release for Windows 7 / check-assets (push) Waiting to run
Build and Release for Windows 7 / build (win7-32, 386, windows) (push) Blocked by required conditions
Build and Release for Windows 7 / build (win7-64, amd64, windows) (push) Blocked by required conditions
Build and Release / check-assets (push) Waiting to run
Build and Release / build (386, freebsd, ) (push) Blocked by required conditions
Build and Release / build (386, linux, ) (push) Blocked by required conditions
Build and Release / build (386, openbsd, ) (push) Blocked by required conditions
Build and Release / build (386, windows, ) (push) Blocked by required conditions
Build and Release / build (amd64, android, android-amd64) (push) Blocked by required conditions
Build and Release / build (amd64, darwin, ) (push) Blocked by required conditions
Build and Release / build (amd64, freebsd, ) (push) Blocked by required conditions
Build and Release / build (amd64, linux, ) (push) Blocked by required conditions
Build and Release / build (amd64, openbsd, ) (push) Blocked by required conditions
Build and Release / build (amd64, windows, ) (push) Blocked by required conditions
Build and Release / build (arm, 5, linux) (push) Blocked by required conditions
Build and Release / build (arm, 6, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, freebsd) (push) Blocked by required conditions
Build and Release / build (arm, 7, linux) (push) Blocked by required conditions
Build and Release / build (arm, 7, openbsd) (push) Blocked by required conditions
Build and Release / build (arm64, android) (push) Blocked by required conditions
Build and Release / build (arm64, darwin) (push) Blocked by required conditions
Build and Release / build (arm64, freebsd) (push) Blocked by required conditions
Build and Release / build (arm64, linux) (push) Blocked by required conditions
Build and Release / build (arm64, openbsd) (push) Blocked by required conditions
Build and Release / build (arm64, windows) (push) Blocked by required conditions
Build and Release / build (loong64, linux) (push) Blocked by required conditions
Build and Release / build (mips, linux) (push) Blocked by required conditions
Build and Release / build (mips64, linux) (push) Blocked by required conditions
Build and Release / build (mips64le, linux) (push) Blocked by required conditions
Build and Release / build (mipsle, linux) (push) Blocked by required conditions
Build and Release / build (ppc64, linux) (push) Blocked by required conditions
Build and Release / build (ppc64le, linux) (push) Blocked by required conditions
Build and Release / build (riscv64, linux) (push) Blocked by required conditions
Build and Release / build (s390x, linux) (push) Blocked by required conditions
Tests and Checkings / check-assets (push) Waiting to run
Tests and Checkings / check-proto (push) Waiting to run
Tests and Checkings / check-format (push) Waiting to run
Tests and Checkings / test (macos-latest) (push) Blocked by required conditions
Tests and Checkings / test (ubuntu-latest) (push) Blocked by required conditions
Tests and Checkings / test (windows-latest) (push) Blocked by required conditions
https://github.com/XTLS/Xray-core/pull/6057#issuecomment-4364819830 And https://github.com/XTLS/Xray-core/pull/6149#issuecomment-4546876261
86 lines
2 KiB
Go
86 lines
2 KiB
Go
package stats_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
. "github.com/xtls/xray-core/app/stats"
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/features/stats"
|
|
)
|
|
|
|
func TestInterface(t *testing.T) {
|
|
_ = stats.Manager(new(Manager))
|
|
}
|
|
|
|
func TestStatsChannelRunnable(t *testing.T) {
|
|
raw, err := common.CreateObject(context.Background(), &Config{})
|
|
common.Must(err)
|
|
|
|
m := raw.(stats.Manager)
|
|
|
|
ch1, err := m.RegisterChannel("test.channel.1")
|
|
c1 := ch1.(*Channel)
|
|
common.Must(err)
|
|
|
|
if c1.Running() {
|
|
t.Fatalf("unexpected running channel: test.channel.%d", 1)
|
|
}
|
|
|
|
common.Must(m.Start())
|
|
|
|
if !c1.Running() {
|
|
t.Fatalf("unexpected non-running channel: test.channel.%d", 1)
|
|
}
|
|
|
|
ch2, err := m.RegisterChannel("test.channel.2")
|
|
c2 := ch2.(*Channel)
|
|
common.Must(err)
|
|
|
|
if !c2.Running() {
|
|
t.Fatalf("unexpected non-running channel: test.channel.%d", 2)
|
|
}
|
|
|
|
s1, err := c1.Subscribe()
|
|
common.Must(err)
|
|
common.Must(c1.Close())
|
|
|
|
if c1.Running() {
|
|
t.Fatalf("unexpected running channel: test.channel.%d", 1)
|
|
}
|
|
|
|
select { // Check all subscribers in closed channel are closed
|
|
case _, ok := <-s1:
|
|
if ok {
|
|
t.Fatalf("unexpected non-closed subscriber in channel: test.channel.%d", 1)
|
|
}
|
|
case <-time.After(500 * time.Millisecond):
|
|
t.Fatalf("unexpected non-closed subscriber in channel: test.channel.%d", 1)
|
|
}
|
|
|
|
if len(c1.Subscribers()) != 0 { // Check subscribers in closed channel are emptied
|
|
t.Fatalf("unexpected non-empty subscribers in channel: test.channel.%d", 1)
|
|
}
|
|
|
|
common.Must(m.Close())
|
|
|
|
if c2.Running() {
|
|
t.Fatalf("unexpected running channel: test.channel.%d", 2)
|
|
}
|
|
|
|
ch3, err := m.RegisterChannel("test.channel.3")
|
|
c3 := ch3.(*Channel)
|
|
common.Must(err)
|
|
|
|
if c3.Running() {
|
|
t.Fatalf("unexpected running channel: test.channel.%d", 3)
|
|
}
|
|
|
|
common.Must(c3.Start())
|
|
common.Must(m.UnregisterChannel("test.channel.3"))
|
|
|
|
if c3.Running() { // Test that unregistering will close the channel.
|
|
t.Fatalf("unexpected running channel: test.channel.%d", 3)
|
|
}
|
|
}
|