Skip to content

Commit 0711ef4

Browse files
Arlet2piotrpio
authored andcommitted
[IMPROVED] Add test veryfying if mirror can be updated to regular stream
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
1 parent 3d0a13a commit 0711ef4

File tree

3 files changed

+91
-13
lines changed

3 files changed

+91
-13
lines changed

go_test.mod

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
module github.com/nats-io/nats.go
22

3-
go 1.23.0
3+
go 1.24.0
4+
5+
toolchain go1.24.7
46

57
require (
68
github.com/golang/protobuf v1.4.2
79
github.com/klauspost/compress v1.18.0
8-
github.com/nats-io/jwt/v2 v2.7.4
9-
github.com/nats-io/nats-server/v2 v2.11.8
10+
github.com/nats-io/jwt/v2 v2.8.0
11+
github.com/nats-io/nats-server/v2 v2.12.0-preview.2.0.20250910084245-518408273bfb
1012
github.com/nats-io/nkeys v0.4.11
1113
github.com/nats-io/nuid v1.0.1
1214
google.golang.org/protobuf v1.23.0
1315
)
1416

1517
require (
18+
github.com/antithesishq/antithesis-sdk-go v0.4.3-default-no-op // indirect
1619
github.com/google/go-tpm v0.9.5 // indirect
1720
github.com/minio/highwayhash v1.0.3 // indirect
1821
golang.org/x/crypto v0.41.0 // indirect
19-
golang.org/x/sys v0.35.0 // indirect
20-
golang.org/x/time v0.12.0 // indirect
22+
golang.org/x/sys v0.36.0 // indirect
23+
golang.org/x/time v0.13.0 // indirect
2124
)

go_test.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zt
1818
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
1919
github.com/minio/highwayhash v1.0.3 h1:kbnuUMoHYyVl7szWjSxJnxw11k2U709jqFPPmIUyD6Q=
2020
github.com/minio/highwayhash v1.0.3/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0rxU3ik1LQ=
21-
github.com/nats-io/jwt/v2 v2.7.4 h1:jXFuDDxs/GQjGDZGhNgH4tXzSUK6WQi2rsj4xmsNOtI=
22-
github.com/nats-io/jwt/v2 v2.7.4/go.mod h1:me11pOkwObtcBNR8AiMrUbtVOUGkqYjMQZ6jnSdVUIA=
23-
github.com/nats-io/nats-server/v2 v2.11.8 h1:7T1wwwd/SKTDWW47KGguENE7Wa8CpHxLD1imet1iW7c=
24-
github.com/nats-io/nats-server/v2 v2.11.8/go.mod h1:C2zlzMA8PpiMMxeXSz7FkU3V+J+H15kiqrkvgtn2kS8=
21+
github.com/nats-io/jwt/v2 v2.8.0 h1:K7uzyz50+yGZDO5o772eRE7atlcSEENpL7P+b74JV1g=
22+
github.com/nats-io/jwt/v2 v2.8.0/go.mod h1:me11pOkwObtcBNR8AiMrUbtVOUGkqYjMQZ6jnSdVUIA=
23+
github.com/nats-io/nats-server/v2 v2.12.0-preview.2.0.20250910084245-518408273bfb h1:I4Wg2P8YlAyvny/47QNoTJP5M9KFdl4v7hCNkjxcSVs=
24+
github.com/nats-io/nats-server/v2 v2.12.0-preview.2.0.20250910084245-518408273bfb/go.mod h1:KV8jyty6TP3Mtd+Cb/gZAiBcRKTuN9YFL0JO0lJgKv4=
2525
github.com/nats-io/nkeys v0.4.11 h1:q44qGV008kYd9W1b1nEBkNzvnWxtRSQ7A8BoqRrcfa0=
2626
github.com/nats-io/nkeys v0.4.11/go.mod h1:szDimtgmfOi9n25JpfIdGw12tZFYXqhGxjhVxsatHVE=
2727
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
2828
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
2929
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
3030
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
3131
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
32-
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
33-
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
34-
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
35-
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
32+
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
33+
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
34+
golang.org/x/time v0.13.0 h1:eUlYslOIt32DgYD6utsuUeHs4d7AsEYLuIAdg7FlYgI=
35+
golang.org/x/time v0.13.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
3636
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
3737
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
3838
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=

jetstream/test/jetstream_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,3 +2403,78 @@ func TestCreateOrUpdateStreamCrossDomains(t *testing.T) {
24032403
t.Fatalf("Expected subject to be updated to 'bar', got %q", info2.Config.Subjects[0])
24042404
}
24052405
}
2406+
2407+
func TestPromoteMirrorToStream(t *testing.T) {
2408+
srv := RunBasicJetStreamServer()
2409+
defer shutdownJSServerAndRemoveStorage(t, srv)
2410+
nc, err := nats.Connect(srv.ClientURL())
2411+
if err != nil {
2412+
t.Fatalf("Unexpected error: %v", err)
2413+
}
2414+
defer nc.Close()
2415+
2416+
js, err := jetstream.New(nc)
2417+
if err != nil {
2418+
t.Fatalf("Unexpected error: %v", err)
2419+
}
2420+
2421+
ctx := context.Background()
2422+
// Create source stream
2423+
_, err = js.CreateStream(ctx, jetstream.StreamConfig{
2424+
Name: "SOURCE",
2425+
Subjects: []string{"foo"},
2426+
})
2427+
if err != nil {
2428+
t.Fatalf("Unexpected error: %v", err)
2429+
}
2430+
2431+
// Publish some messages to source
2432+
for range 10 {
2433+
if _, err := js.Publish(ctx, "foo", []byte("hello")); err != nil {
2434+
t.Fatalf("Unexpected error: %v", err)
2435+
}
2436+
}
2437+
2438+
// Create mirror stream
2439+
mirror, err := js.CreateStream(ctx, jetstream.StreamConfig{
2440+
Name: "MIRROR",
2441+
Mirror: &jetstream.StreamSource{Name: "SOURCE"},
2442+
})
2443+
if err != nil {
2444+
t.Fatalf("Unexpected error: %v", err)
2445+
}
2446+
2447+
// Wait for mirror to catch up
2448+
checkFor(t, 5*time.Second, 100*time.Millisecond, func() error {
2449+
info, err := mirror.Info(ctx)
2450+
if err != nil {
2451+
return err
2452+
}
2453+
if info.State.Msgs != 10 {
2454+
return fmt.Errorf("not caught up")
2455+
}
2456+
return nil
2457+
})
2458+
2459+
// Remove mirror configuration
2460+
updatedMirror, err := js.UpdateStream(ctx, jetstream.StreamConfig{
2461+
Name: "MIRROR",
2462+
Subjects: []string{"bar"},
2463+
})
2464+
if err != nil {
2465+
t.Fatalf("Unexpected error: %v", err)
2466+
}
2467+
2468+
info, err := updatedMirror.Info(ctx)
2469+
if err != nil {
2470+
t.Fatalf("Unexpected error: %v", err)
2471+
}
2472+
2473+
if info.Config.Mirror != nil {
2474+
t.Fatal("Expected mirror to be nil after promote")
2475+
}
2476+
2477+
if info.Config.Subjects[0] != "bar" {
2478+
t.Fatalf("Expected subject to be 'bar', got %q", info.Config.Subjects[0])
2479+
}
2480+
}

0 commit comments

Comments
 (0)