Fix signup registration receipts and activation worker lifetime (#57)
This commit is contained in:
1 parent
bd675357bb
commit
abca15f047
6 files changed
+148
-13
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
merrors "git.sendico.io/tech/sxchnge/shared/errors"
|
||||
"git.sendico.io/tech/sxchnge/shared/messaging/reliable"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type outbox struct{ jobs []model.Notification }
|
||||
@@ -23,6 +24,50 @@ type publisher struct {
|
||||
records []reliable.Record
|
||||
}
|
||||
|
||||
type consumerTransport struct {
|
||||
reliable.Transport
|
||||
reliable.Subscription
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (t *consumerTransport) OpenConsumer(ctx context.Context, _ reliable.DurableSettings, _ reliable.DurableConsumerSettings) (reliable.Subscription, error) {
|
||||
t.ctx = ctx
|
||||
return t.Subscription, nil
|
||||
}
|
||||
|
||||
type consumerAdmin struct {
|
||||
reliable.Admin
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (a *consumerAdmin) EnsureConsumerResources(ctx context.Context, _ reliable.DurableSettings, _ reliable.DurableConsumerSettings) error {
|
||||
a.ctx = ctx
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestSubscriptionOutlivesProvisioning(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
transport := &consumerTransport{}
|
||||
admin := &consumerAdmin{}
|
||||
if _, err := New(ctx, transport, admin, &outbox{}, nil, zap.NewNop(), DefaultConfig()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if admin.ctx.Err() != context.Canceled {
|
||||
t.Fatal("provisioning context was not released")
|
||||
}
|
||||
if _, ok := admin.ctx.Deadline(); !ok {
|
||||
t.Fatal("provisioning has no deadline")
|
||||
}
|
||||
if err := transport.ctx.Err(); err != nil {
|
||||
t.Fatalf("subscription ended with provisioning: %v", err)
|
||||
}
|
||||
cancel()
|
||||
if transport.ctx.Err() != context.Canceled {
|
||||
t.Fatal("subscription does not follow service shutdown")
|
||||
}
|
||||
}
|
||||
|
||||
func (p *publisher) Publish(_ context.Context, r reliable.Record) error {
|
||||
if p.fail {
|
||||
return merrors.ServiceUnavailable("offline")
|
||||
|
||||
Reference in new issue
Block a user