39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
|
|
"mesh-delivery-builder/internal/versions"
|
|
)
|
|
|
|
// Design 47 H2 H-A-720 (1), H-A-741: a mark is updated by one publish carrying its lifetime and the expected last sequence of its
|
|
// key: the update at the right revision succeeds and the key keeps its lifetime; one at a stale revision is a conflict.
|
|
func TestAMarkIsUpdatedWithItsLifetimeInOnePublish(t *testing.T) {
|
|
b := startBed(t)
|
|
kv, err := b.js.CreateKeyValue(b.ctx, jetstream.KeyValueConfig{Bucket: "acted-test", LimitMarkerTTL: time.Minute})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
key := versions.ActedKey("retake:x")
|
|
rev, err := kv.Create(b.ctx, key, []byte("1"), jetstream.KeyTTL(time.Hour))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
next, err := updateWithLifetime(b.ctx, b.js, "acted-test", key, []byte("2"), rev, 2*time.Hour)
|
|
if err != nil || next <= rev {
|
|
t.Fatalf("update at the key's revision: %d, %v", next, err)
|
|
}
|
|
if e, err := kv.Get(b.ctx, key); err != nil || string(e.Value()) != "2" || e.Revision() != next {
|
|
t.Fatalf("the key holds %v, %v after the update", e, err)
|
|
}
|
|
if _, err := updateWithLifetime(b.ctx, b.js, "acted-test", key, []byte("3"), rev, time.Hour); !errors.Is(err, versions.ErrConflict) {
|
|
t.Fatalf("update at a stale revision: %v, want a conflict", err)
|
|
}
|
|
}
|