singleflighttest

package
v0.34.0 Latest Latest
Warning

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

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

Documentation

Overview

Package singleflighttest 是 singleflight 语义的共享契约测试套件。

矩阵内存在两份等价实现(concurrency/singleflight 公开版与 pkg/internal/singleflight fork,fork 因 pkg 零依赖约束而保留)。本包把 关键语义固化为可复用的 Run,双方 CI 各自调用,任一侧语义漂移立刻双红。 先例:pkg/cache/cachetest。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run[T any](t *testing.T, factory func() Flight[T])

Run 对 factory 构造出的 Flight 跑完整语义契约。factory 每个子测试调用一次。

契约清单:

  • 同 key 并发 fn 只执行一次
  • waiter 独立 ctx 取消不连坐(不拖垮 caller/其他 waiter)
  • lead panic:waiter 得 error(非伪成功零值),caller 收到 panic,key 清理
  • Forget 后可重入新 fn
  • **Forget 竞态**:旧 call 的收尾不得删掉新注册的 call(#147)
  • 不同 key 互不阻塞
  • fn error 原样透传给全部调用方
  • **一次飞行结束后,新调用必须重新执行 fn**(key 已释放,不得复用上次的 结果)

Types

type Flight

type Flight[T any] interface {
	Do(ctx context.Context, key string, fn func(ctx context.Context) (T, error)) (T, error)
	Forget(key string)
}

Flight 是被测 singleflight 的最小能力面,与 concurrency/singleflight.Flight 和 pkg/internal/singleflight.Flight 对齐。

Jump to

Keyboard shortcuts

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