notify/file_transfer_config_test.go
starainrt 09d972c7b7
feat(notify): 重构通信内核并补齐 stream/bulk/record/transfer 能力
- 引入 LogicalConn/TransportConn 分层,ClientConn 保留兼容适配层
  - 新增 Stream、Bulk、RecordStream 三条数据面能力及对应控制路径
  - 完成 transfer/file 传输内核与状态快照、诊断能力
  - 补齐 reconnect、inbound dispatcher、modern psk 等基础模块
  - 增加大规模回归、并发与基准测试覆盖
  - 更新依赖库
2026-04-15 15:24:36 +08:00

105 lines
3.4 KiB
Go

package notify
import (
"context"
"os"
"path/filepath"
"reflect"
"testing"
"time"
)
func TestClientFileTransferConfigDefaults(t *testing.T) {
client := NewClient().(*ClientCommon)
cfg := client.getFileTransferConfig()
if got, want := cfg.ChunkSize, defaultFileChunkSize; got != want {
t.Fatalf("chunk size mismatch: got %d want %d", got, want)
}
if got, want := cfg.AckTimeout, defaultFileAckTimeout; got != want {
t.Fatalf("ack timeout mismatch: got %v want %v", got, want)
}
if got, want := cfg.SendRetry, defaultFileSendRetry; got != want {
t.Fatalf("send retry mismatch: got %d want %d", got, want)
}
if got, want := cfg.ReceiveCompletedLimit, defaultFileReceiveCompletedLimit; got != want {
t.Fatalf("receive completed limit mismatch: got %d want %d", got, want)
}
if got, want := cfg.MonitorCompletedLimit, defaultFileTransferCompletedLimit; got != want {
t.Fatalf("monitor completed limit mismatch: got %d want %d", got, want)
}
}
func TestServerFileTransferConfigNormalization(t *testing.T) {
server := NewServer().(*ServerCommon)
server.setFileTransferConfig(fileTransferConfig{})
cfg := server.getFileTransferConfig()
if got, want := cfg.ChunkSize, defaultFileChunkSize; got != want {
t.Fatalf("normalized chunk size mismatch: got %d want %d", got, want)
}
if got, want := cfg.AckTimeout, defaultFileAckTimeout; got != want {
t.Fatalf("normalized ack timeout mismatch: got %v want %v", got, want)
}
if got, want := cfg.SendRetry, defaultFileSendRetry; got != want {
t.Fatalf("normalized retry mismatch: got %d want %d", got, want)
}
if got, want := cfg.ReceiveCompletedLimit, defaultFileReceiveCompletedLimit; got != want {
t.Fatalf("normalized receive completed limit mismatch: got %d want %d", got, want)
}
if got, want := cfg.MonitorCompletedLimit, defaultFileTransferCompletedLimit; got != want {
t.Fatalf("normalized monitor completed limit mismatch: got %d want %d", got, want)
}
}
func TestClientFileTransferConfigPropagatesRetentionLimits(t *testing.T) {
client := NewClient().(*ClientCommon)
client.setFileTransferConfig(fileTransferConfig{
ChunkSize: 64,
AckTimeout: time.Second,
SendRetry: 2,
ReceiveCompletedLimit: 7,
MonitorCompletedLimit: 9,
})
if got, want := client.getFileReceivePool().completedLimit, 7; got != want {
t.Fatalf("client receive pool completed limit mismatch: got %d want %d", got, want)
}
if got, want := client.getFileTransferState().monitorView().completedLimit, 9; got != want {
t.Fatalf("client transfer monitor completed limit mismatch: got %d want %d", got, want)
}
}
func TestSendFileWithHooksHonorsConfiguredChunkSize(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "payload.bin")
if err := os.WriteFile(path, []byte("abcdefg"), 0o600); err != nil {
t.Fatalf("write temp file failed: %v", err)
}
var chunks []int
err := sendFileWithHooks(context.Background(), path, fileSendHooks{
config: fileTransferConfig{
ChunkSize: 3,
AckTimeout: time.Millisecond,
SendRetry: 1,
},
sendReliable: func(ctx context.Context, env Envelope) error {
if env.Kind == EnvelopeFileChunk {
chunks = append(chunks, len(env.File.Chunk))
}
return nil
},
})
if err != nil {
t.Fatalf("sendFileWithHooks failed: %v", err)
}
if got, want := chunks, []int{3, 3, 1}; !reflect.DeepEqual(got, want) {
t.Fatalf("chunk sizes mismatch: got %v want %v", got, want)
}
}