fix(core): паника горутины больше не убивает процесс приложения

This commit is contained in:
samosvalishe committed 2026-08-25 15:44:16 +03:00
1 parent 623ef46f2f
commit 748d5a07ce
9 files changed
+176 -23

No files matched your search

+20
View File
@@ -2,12 +2,14 @@ package session
import (
"context"
"errors"
"sync"
"testing"
"time"
"github.com/samosvalishe/free-turn-proxy/internal/config"
"github.com/samosvalishe/free-turn-proxy/internal/netconn"
"github.com/samosvalishe/free-turn-proxy/internal/safego"
)
func newTestSession(t *testing.T, opts Options, captcha func() bool) *Session {
@@ -305,3 +307,21 @@ func TestTrafficRates(t *testing.T) {
t.Fatalf("idle rates = tx %d rx %d, want zero", tx, rx)
}
}
// Паника в попытке релея не должна валить процесс приложения: ядро - библиотека внутри
// процесса UI, перехватить снаружи нечем.
func TestRelayLoopTurnsPanicIntoError(t *testing.T) {
s := newTestSession(t, Options{}, nil)
errCh := make(chan error, 1)
go func() { errCh <- s.relayLoop(context.Background(), func(context.Context) error { panic("boom") }) }()
select {
case err := <-errCh:
if !errors.Is(err, safego.ErrPanic) {
t.Fatalf("relayLoop() error = %v, want ErrPanic", err)
}
case <-time.After(5 * time.Second):
t.Fatal("relayLoop() hung on panic")
}
}