Deterministic simulation and model testing toolkit for MoonBit.
| 工具或方向 | moonsim 对应提供的能力 | moonsim 的组合增强 |
|---|---|---|
| Akka TestKit | 消息探测、时序断言和失败路径验证 | 同一事件流还能表达任务、定时器、状态转移与外部调用,并保留跨组件因果关系 |
| Python SimPy | 虚拟时间、事件调度和确定性执行 | 面向软件可靠性直接提供 seed 变异、invariant、trace digest 与失败重放,无需自行拼装测试闭环 |
| Java DESMO-J、CloudSim | 离散事件排序、调度和容量场景运行 | 以轻量 MoonBit API 聚焦消息、工作流和状态机,可直接进入 moon test 与现有 CI |
| Haskell QuickCheck、Python Hypothesis | 用属性或 invariant 判断大量执行结果 | 失败证据同时保存 seed、策略、关键事件和 digest,可在相同输入、配置和代码版本下确定性 replay |
| Jepsen 风格模型验证 | 通过历史事件检查系统规则是否成立 | 在纯模型中快速枚举延迟、丢弃、重复、乱序和失败组合,适合在开发与 CI 阶段高频回归 |
| 手写 mock、fake clock | 替换依赖、控制时间和构造异常返回 | 把时间、五类事件、因果关系、变异、证据与 replay 做成公共框架,减少重复测试基础设施 |
moon new moonsim-consumer
Set-Location moonsim-consumer
moon add zlhahaha/moonsim@0.3.1import {
"zlhahaha/moonsim",
}fn main {
let stream = @moonsim.event_stream()
let sent = stream.record(
@moonsim.message_event_kind(), 0, "message.send",
correlation_id="order-42", source="producer", target="worker",
)
ignore(stream.record(
@moonsim.task_event_kind(), 3, "task.complete",
correlation_id="order-42", parent_id=sent.id,
))
let policy = @moonsim.event_mutation_policy(
seed=2026UL, duplicate_percent=100,
)
let result = stream.replay(policy)
let failure = @moonsim.event_failure_case(
"order_completed_once", stream, policy,
)
let replay = failure.replay()
println("failed_rule=" + failure.rule)
println("digest=" + result.digest.to_string())
println("same_seed=" + result.matches_digest(replay).to_string())
}moon check --deny-warn
moon run cmd/mainfailed_rule=order_completed_once
same_seed=true| 能力 | 可运行证据 | 测试或文档证据 |
|---|---|---|
| 五类事件、稳定排序与因果关系 | moon run cmd/main | API 文档、core/event_stream_test.mbt |
| seed 变异、digest 与失败重放 | moon run examples/queue | core/event_stream_test.mbt、models/event_stream_test.mbt |
| 消息重复投递、确认、重试与死信 | moon run examples/queue | models/event_stream_test.mbt |
| 任务依赖、取消与终态保护 | moon run examples/workflow | models/event_stream_test.mbt |
| HTTP 记录重放兼容适配 | moon run examples/service_resilience | models/event_stream_test.mbt、教程 |
| 10k smoke 与 1k/10k/100k 容量观测 | moon run cmd/benchmark | core/event_stream_test.mbt |
moon run examples/queue
moon run examples/workflow
moon run cmd/mainmoon fmt
moon check --deny-warn
moon build
moon info
git diff --exit-code
moon test --deny-warn
moon run cmd/main
moon run examples/queue
moon run examples/workflow
moon run examples/service_resilience
moon run cmd/benchmarkfn circuit_breaker_config(failure_threshold? : Int, reset_timeout? : Int, half_open_successes? : Int) -> CircuitBreakerConfigfn compare_forks(left_name : String, left : Sim, right_name : String, right : Sim) -> ForkComparisonfn demo_descriptor(name : String, command : String, purpose : String, features : Array[String]) -> DemoDescriptorfn event_failure_case(rule : String, source : EventStream, policy : EventMutationPolicy) -> EventFailureCasefn event_mutation_policy(seed? : UInt64, max_delay? : Int, delay_percent? : Int, drop_percent? : Int, duplicate_percent? : Int, reorder_same_tick? : Bool, failure_percent? : Int) -> EventMutationPolicyfn expect_trace_kind_count(entries : Array[TraceEntry], kind : String, expected : Int) -> TraceExpectationfn expect_trace_order(entries : Array[TraceEntry], before : String, after : String) -> TraceExpectationfn http_reliability_policy(seed? : UInt64, retry_limit? : Int, timeout_ticks? : Int, backoff_ticks? : Int, deadline_ticks? : Int, rate_limit_per_tick? : Int, circuit_failure_threshold? : Int, circuit_reset_ticks? : Int, accept_late_success? : Bool) -> HttpReliabilityPolicyfn http_replay_options(latency_jitter? : Int, injected_failure_percent? : Int, reverse_same_tick_order? : Bool) -> HttpReplayOptionsfn load_balancer_config(seed? : UInt64, jobs? : Int, workers? : Int, max_arrival_gap? : Int, min_service? : Int, max_service? : Int, strategy? : String) -> LoadBalancerConfigfn network_config(seed? : UInt64, messages? : Int, latency_min? : Int, latency_max? : Int, drop_percent? : Int, retry_delay? : Int) -> NetworkConfigfn queue_config(seed? : UInt64, customers? : Int, max_arrival_gap? : Int, service_time? : Int) -> QueueConfigfn recorded_http_exchange(request : HttpRequest, outcome : HttpOutcome, started_tick? : Int, latency_ticks? : Int) -> RecordedHttpExchangefn recorded_http_transport(scenario : String, exchanges : Array[RecordedHttpExchange], options? : HttpReplayOptions) -> RecordedHttpTransportfn reliability_config(seed? : UInt64, operations? : Int, fail_percent? : Int, retry_limit? : Int, backoff? : Int) -> ReliabilityConfigfn retry_config(seed? : UInt64, max_attempts? : Int, fail_until? : Int, initial_backoff? : Int, jitter? : Int) -> RetryConfigfn service_resilience_config(seed? : UInt64, requests? : Int, workers? : Int, queue_limit? : Int, timeout_ticks? : Int, retry_limit? : Int, base_latency? : Int, jitter? : Int, fail_percent? : Int, drop_percent? : Int, rate_limit_capacity? : Int, rate_limit_refill? : Int, rate_limit_interval? : Int, min_success_percent? : Int) -> ServiceResilienceConfigfn timer_plan(name : String, start_after? : Int, interval? : Int, times? : Int, priority? : Int) -> TimerPlanfn trace_filter_tick_range(entries : Array[TraceEntry], min_tick : Int, max_tick : Int) -> Array[TraceEntry]Deterministic simulation and model testing toolkit for MoonBit.