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

Function TestPublishWithTTL

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

Source from the content-addressed store, hash-verified

431}
432
433func TestPublishWithTTL(t *testing.T) {
434 srv := RunBasicJetStreamServer()
435 defer shutdownJSServerAndRemoveStorage(t, srv)
436 nc, js := jsClient(t, srv)
437 defer nc.Close()
438
439 _, err := js.AddStream(&nats.StreamConfig{
440 Name: "foo", Subjects: []string{"FOO.*"}, MaxMsgSize: 64, AllowMsgTTL: true})
441 if err != nil {
442 t.Fatalf("Unexpected error: %v", err)
443 }
444
445 ack, err := js.Publish("FOO.1", []byte("msg"), nats.MsgTTL(1*time.Second))
446 if err != nil {
447 t.Fatalf("Unexpected error: %v", err)
448 }
449 gotMsg, err := js.GetMsg("foo", ack.Sequence)
450 if err != nil {
451 t.Fatalf("Unexpected error: %v", err)
452 }
453 if ttl := gotMsg.Header.Get("Nats-TTL"); ttl != "1s" {
454 t.Fatalf("Expected message to have TTL header set to 1s; got: %s", ttl)
455 }
456 time.Sleep(1500 * time.Millisecond)
457 _, err = js.GetMsg("foo", ack.Sequence)
458 if !errors.Is(err, nats.ErrMsgNotFound) {
459 t.Fatalf("Expected not found error; got: %v", err)
460 }
461}
462
463func TestMsgDeleteMarkerMaxAge(t *testing.T) {
464 srv := RunBasicJetStreamServer()

Callers

nothing calls this directly

Calls 10

FatalfMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
jsClientFunction · 0.70
AddStreamMethod · 0.65
PublishMethod · 0.65
GetMsgMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected