alby-hub/nip47/publish_nip47_info_test.go
Michael Bumann bc49cb7d33
fix: stop retrying NIP47 info publish for deleted apps (#2391)
The NIP47 info publish queue re-enqueued every failed publish with an
incrementing backoff and no terminal condition. When an app connection
was deleted, PublishNip47Info fails the `db.First(&app, appId)` lookup
with gorm.ErrRecordNotFound on every attempt, so the item was retried
forever (observed as a steady stream of "Failed to publish NIP47 info
from queue" errors from affected instances).

Drop the queue item when the app no longer exists instead of requeuing.
All other errors (offline relay, timeouts) still retry with backoff.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 13:29:05 +07:00

36 lines
1.2 KiB
Go

package nip47
import (
"context"
"testing"
"github.com/getAlby/go-nostr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
"github.com/getAlby/hub/alby"
"github.com/getAlby/hub/tests"
)
// When an app connection has been deleted, publishing its NIP47 info must
// surface gorm.ErrRecordNotFound so the publish queue can drop the item
// instead of retrying forever.
func TestPublishNip47Info_AppNotFound(t *testing.T) {
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
albyOAuthSvc := alby.NewAlbyOAuthService(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher)
nip47svc := NewNip47Service(svc.DB, svc.Cfg, svc.Keys, svc.EventPublisher, albyOAuthSvc)
walletPrivKey := nostr.GeneratePrivateKey()
walletPubKey, err := nostr.GetPublicKey(walletPrivKey)
require.NoError(t, err)
// app id 9999999 does not exist; the DB lookup fails before the relay pool
// is ever used, so a nil pool/lnClient is fine here.
_, err = nip47svc.PublishNip47Info(context.Background(), nil, 9999999, walletPubKey, walletPrivKey, "wss://relay.example.com", nil)
require.Error(t, err)
assert.ErrorIs(t, err, gorm.ErrRecordNotFound)
}