MCPcopy
hub / github.com/nats-io/nats.go / TestJetStreamClusterStreamLeaderChangeClientErr

Function TestJetStreamClusterStreamLeaderChangeClientErr

test/js_test.go:9672–9761  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9670}
9671
9672func TestJetStreamClusterStreamLeaderChangeClientErr(t *testing.T) {
9673 t.Skip("The 2.9 server changed behavior making this test fail now")
9674
9675 cfg := &nats.StreamConfig{
9676 Name: "TEST",
9677 Subjects: []string{"foo"},
9678 Replicas: 3,
9679 }
9680
9681 withJSClusterAndStream(t, "R3S", 3, cfg, func(t *testing.T, stream string, servers ...*jsServer) {
9682 // We want to make sure the worse thing seen by the lower levels during a leadership change is NoResponders.
9683 // We will have three concurrent contexts going on.
9684 // 1. Leadership Changes every 500ms.
9685 // 2. Publishing messages to the stream every 10ms.
9686 // 3. StreamInfo calls every 15ms.
9687 expires := time.Now().Add(5 * time.Second)
9688 var wg sync.WaitGroup
9689 wg.Add(3)
9690
9691 randServer := func() *server.Server {
9692 return servers[mrand.Intn(len(servers))].Server
9693 }
9694
9695 // Leadership changes.
9696 go func() {
9697 defer wg.Done()
9698 nc, js := jsClient(t, randServer())
9699 defer nc.Close()
9700
9701 sds := fmt.Sprintf(server.JSApiStreamLeaderStepDownT, "TEST")
9702 for time.Now().Before(expires) {
9703 time.Sleep(500 * time.Millisecond)
9704 si, err := js.StreamInfo("TEST")
9705 expectOk(t, err)
9706 _, err = nc.Request(sds, nil, time.Second)
9707 expectOk(t, err)
9708
9709 // Wait on new leader.
9710 checkFor(t, 5*time.Second, 50*time.Millisecond, func() error {
9711 si, err = js.StreamInfo("TEST")
9712 if err != nil {
9713 return err
9714 }
9715 if si.Cluster.Leader == "" {
9716 return errors.New("No leader yet")
9717 }
9718 return nil
9719 })
9720 }
9721 }()
9722
9723 // Published every 10ms
9724 toc := 0
9725 go func() {
9726 defer wg.Done()
9727 nc, js := jsClient(t, randServer())
9728 defer nc.Close()
9729

Callers

nothing calls this directly

Calls 11

FatalfMethod · 0.80
withJSClusterAndStreamFunction · 0.70
jsClientFunction · 0.70
expectOkFunction · 0.70
checkForFunction · 0.70
AddMethod · 0.65
DoneMethod · 0.65
StreamInfoMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45
RequestMethod · 0.45

Tested by

no test coverage detected