testutil

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package testutil 提供进程内嵌 etcd 服务端(embed),供各包单元测试使用, 不进入公共 API(internal)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(t *testing.T) *clientv3.Client

NewClient 启动一个内嵌 etcd 实例并返回已连接的客户端;测试结束时自动 关停服务端与客户端。

Types

type Server added in v0.2.8

type Server struct {
	// contains filtered or unexported fields
}

Server 是一个可重启的内嵌 etcd 测试服务端:同一数据目录 + 同一端口重启 (模拟 etcd-server 重启/抖动),MVCC 数据与压缩点跨重启保留,客户端自动 重连。

func NewServer added in v0.2.8

func NewServer(t *testing.T) *Server

NewServer 启动一个内嵌 etcd 实例并返回服务端句柄;测试结束时自动关停。 端口由内核随机分配,数据目录为 t.TempDir()(自动清理)。

func (*Server) Client added in v0.2.8

func (s *Server) Client() *clientv3.Client

Client 返回已连接的客户端(跨重启自动重连同一 endpoint)。

func (*Server) ClientURL added in v0.3.2

func (s *Server) ClientURL() string

ClientURL 返回服务端 client endpoint 地址(127.0.0.1:port),供测试自建 带拦截器等定制项的 clientv3 客户端(如 registry #147 的故障注入探针)。

func (*Server) Restart added in v0.2.8

func (s *Server) Restart(downtime time.Duration)

Restart 重启服务端:先 Close(触发客户端 watch 流断开),空窗 downtime 后以同一数据目录 + 同一端口拉起并等待就绪。客户端自动重连;重连后 clientv3 从其最后收到的 revision 自动恢复(resume)watch——若压缩点已 越过该 revision,服务端会对恢复的 watch 回 Canceled(ErrCompacted), 从而确定性地触发被测代码的 watch 重建路径。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL