Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

server: re-anchor expired storage warning emails

Neeraj Guptac9c7cdbc8fed
diff --git a/server/pkg/controller/email/storage_warning.go b/server/pkg/controller/email/storage_warning.go
index edad8a01f1..f989272db0 100644
--- a/server/pkg/controller/email/storage_warning.go
+++ b/server/pkg/controller/email/storage_warning.go
@@ -45,32 +45,36 @@ const (
)
type storageWarningSnapshot struct {
- RecipientID int64
- AccountEmail string
- TotalUsage int64
- BaseStorage int64
- UsableBonus int64
- AllottedStorage int64
- AvailableStorage int64
- EffectiveExpiry int64
- EvaluatedAt int64
- CurrentBucket storageWarningBucket
- Bucket storageWarningBucket
- ActiveOverageStage activeOverageWarningStage
- ExpiredStage expiredWarningStage
- AutoDeleteDate int64
- IsFamilyPlan bool
- WarningCycleStart int64
- NotificationHistory map[string]int64
+ RecipientID int64
+ AccountEmail string
+ TotalUsage int64
+ BaseStorage int64
+ UsableBonus int64
+ AllottedStorage int64
+ AvailableStorage int64
+ SubscriptionExpiry int64
+ EffectiveExpiry int64
+ ExpiredWarningAnchor int64
+ EvaluatedAt int64
+ CurrentBucket storageWarningBucket
+ Bucket storageWarningBucket
+ ActiveOverageStage activeOverageWarningStage
+ ExpiredStage expiredWarningStage
+ AutoDeleteDate int64
+ IsFamilyPlan bool
+ WarningCycleStart int64
+ NotificationHistory map[string]int64
}
type storageWarningMetrics struct {
- BaseStorage int64
- UsableBonus int64
- AllottedStorage int64
- AvailableStorage int64
- EffectiveExpiry int64
- Bucket storageWarningBucket
+ BaseStorage int64
+ UsableBonus int64
+ AllottedStorage int64
+ AvailableStorage int64
+ SubscriptionExpiry int64
+ EffectiveExpiry int64
+ ExpiredWarningAnchor int64
+ Bucket storageWarningBucket
}
type storageWarningRunStats struct {
@@ -312,18 +316,20 @@ func (c *EmailNotificationController) buildFamilyStorageWarningSnapshot(ctx cont
metrics := computeStorageWarningMetrics(sub, activeBonuses, totalUsage, now)
snapshot := storageWarningSnapshot{
- RecipientID: adminID,
- AccountEmail: admin.Email,
- TotalUsage: totalUsage,
- BaseStorage: metrics.BaseStorage,
- UsableBonus: metrics.UsableBonus,
- AllottedStorage: metrics.AllottedStorage,
- AvailableStorage: metrics.AvailableStorage,
- EffectiveExpiry: metrics.EffectiveExpiry,
- EvaluatedAt: now,
- CurrentBucket: metrics.Bucket,
- Bucket: metrics.Bucket,
- IsFamilyPlan: true,
+ RecipientID: adminID,
+ AccountEmail: admin.Email,
+ TotalUsage: totalUsage,
+ BaseStorage: metrics.BaseStorage,
+ UsableBonus: metrics.UsableBonus,
+ AllottedStorage: metrics.AllottedStorage,
+ AvailableStorage: metrics.AvailableStorage,
+ SubscriptionExpiry: metrics.SubscriptionExpiry,
+ EffectiveExpiry: metrics.EffectiveExpiry,
+ ExpiredWarningAnchor: metrics.ExpiredWarningAnchor,
+ EvaluatedAt: now,
+ CurrentBucket: metrics.Bucket,
+ Bucket: metrics.Bucket,
+ IsFamilyPlan: true,
}
return c.decorateStorageWarningSnapshot(snapshot, now)
}
@@ -357,18 +363,20 @@ func (c *EmailNotificationController) buildIndividualStorageWarningSnapshot(ctx
metrics := computeStorageWarningMetrics(sub, activeBonuses, totalUsage, now)
snapshot := storageWarningSnapshot{
- RecipientID: userID,
- AccountEmail: user.Email,
- TotalUsage: totalUsage,
- BaseStorage: metrics.BaseStorage,
- UsableBonus: metrics.UsableBonus,
- AllottedStorage: metrics.AllottedStorage,
- AvailableStorage: metrics.AvailableStorage,
- EffectiveExpiry: metrics.EffectiveExpiry,
- EvaluatedAt: now,
- CurrentBucket: metrics.Bucket,
- Bucket: metrics.Bucket,
- IsFamilyPlan: false,
+ RecipientID: userID,
+ AccountEmail: user.Email,
+ TotalUsage: totalUsage,
+ BaseStorage: metrics.BaseStorage,
+ UsableBonus: metrics.UsableBonus,
+ AllottedStorage: metrics.AllottedStorage,
+ AvailableStorage: metrics.AvailableStorage,
+ SubscriptionExpiry: metrics.SubscriptionExpiry,
+ EffectiveExpiry: metrics.EffectiveExpiry,
+ ExpiredWarningAnchor: metrics.ExpiredWarningAnchor,
+ EvaluatedAt: now,
+ CurrentBucket: metrics.Bucket,
+ Bucket: metrics.Bucket,
+ IsFamilyPlan: false,
}
return c.decorateStorageWarningSnapshot(snapshot, now)
}
@@ -381,13 +389,13 @@ func (c *EmailNotificationController) decorateStorageWarningSnapshot(snapshot st
return storageWarningSnapshot{}, err
}
snapshot.NotificationHistory = history
- snapshot.WarningCycleStart = snapshot.EffectiveExpiry
- snapshot.ExpiredStage = resolveExpiredWarningStage(snapshot.EffectiveExpiry, now, history)
+ snapshot.WarningCycleStart = snapshot.ExpiredWarningAnchor
+ snapshot.ExpiredStage = resolveExpiredWarningStage(snapshot.ExpiredWarningAnchor, now, history)
if snapshot.ExpiredStage == expiredWarningStageNone {
snapshot.Bucket = storageWarningBucketNone
return snapshot, nil
}
- snapshot.AutoDeleteDate = expiredWarningAutoDeleteDate(snapshot.EffectiveExpiry, snapshot.ExpiredStage, now)
+ snapshot.AutoDeleteDate = expiredWarningAutoDeleteDate(snapshot.ExpiredWarningAnchor, snapshot.ExpiredStage, now)
case storageWarningBucketActiveOverage:
history, err := c.NotificationHistoryRepo.GetLastNotificationTimes(snapshot.RecipientID, activeOverageWarningTemplateIDs())
if err != nil {
@@ -442,7 +450,7 @@ func (c *EmailNotificationController) processStorageWarningSnapshot(snapshot sto
"AllottedStorage": snapshot.AllottedStorage,
"AvailableStorage": snapshot.AvailableStorage,
"AccountEmail": snapshot.AccountEmail,
- "ExpiryDate": formatDate(snapshot.EffectiveExpiry),
+ "ExpiryDate": formatDate(snapshot.SubscriptionExpiry),
"AutoDeleteDate": formatDate(snapshot.AutoDeleteDate),
"IsFamilyPlan": snapshot.IsFamilyPlan,
}
@@ -468,7 +476,9 @@ func (c *EmailNotificationController) processStorageWarningSnapshot(snapshot sto
"overage_trigger_limit_gib": formatStorageGiB(snapshot.AllottedStorage + storageWarningOverageThreshold),
"usage_above_allotted_gib": formatStorageGiB(positiveDelta(snapshot.TotalUsage, snapshot.AllottedStorage)),
"usage_above_trigger_limit_gib": formatStorageGiB(positiveDelta(snapshot.TotalUsage, snapshot.AllottedStorage+storageWarningOverageThreshold)),
+ "subscription_expiry": snapshot.SubscriptionExpiry,
"effective_expiry": snapshot.EffectiveExpiry,
+ "expired_warning_anchor": snapshot.ExpiredWarningAnchor,
"warning_cycle_start": snapshot.WarningCycleStart,
"active_stage": snapshot.ActiveOverageStage,
"expired_stage": snapshot.ExpiredStage,
@@ -512,7 +522,9 @@ func (c *EmailNotificationController) processStorageWarningSnapshot(snapshot sto
func computeStorageWarningMetrics(subscription *ente.Subscription, activeBonuses *bonus.ActiveStorageBonus, totalUsage int64, now int64) storageWarningMetrics {
baseEffectiveExpiry := int64(0)
baseStorage := int64(0)
+ subscriptionExpiry := int64(0)
if subscription != nil {
+ subscriptionExpiry = subscription.ExpiryTime
baseEffectiveExpiry = effectiveSubscriptionExpiry(*subscription)
if baseEffectiveExpiry > now {
baseStorage = subscription.Storage
@@ -526,13 +538,16 @@ func computeStorageWarningMetrics(subscription *ente.Subscription, activeBonuses
usableBonus := activeBonuses.GetUsableBonus(baseStorage)
allottedStorage := baseStorage + usableBonus
+ expiredWarningAnchor := expiredWarningAnchorFromSubscriptionExpiry(subscriptionExpiry)
return storageWarningMetrics{
- BaseStorage: baseStorage,
- UsableBonus: usableBonus,
- AllottedStorage: allottedStorage,
- AvailableStorage: allottedStorage - totalUsage,
- EffectiveExpiry: effectiveExpiry,
- Bucket: bucketStorageWarning(totalUsage, allottedStorage, effectiveExpiry, now),
+ BaseStorage: baseStorage,
+ UsableBonus: usableBonus,
+ AllottedStorage: allottedStorage,
+ AvailableStorage: allottedStorage - totalUsage,
+ SubscriptionExpiry: subscriptionExpiry,
+ EffectiveExpiry: effectiveExpiry,
+ ExpiredWarningAnchor: expiredWarningAnchor,
+ Bucket: bucketStorageWarning(totalUsage, allottedStorage, effectiveExpiry, expiredWarningAnchor, now),
}
}
@@ -544,16 +559,16 @@ func effectiveSubscriptionExpiry(subscription ente.Subscription) int64 {
return expiry
}
-func bucketStorageWarning(totalUsage int64, allottedStorage int64, effectiveExpiry int64, now int64) storageWarningBucket {
+func bucketStorageWarning(totalUsage int64, allottedStorage int64, effectiveExpiry int64, expiredWarningAnchor int64, now int64) storageWarningBucket {
if totalUsage <= allottedStorage+storageWarningOverageThreshold {
return storageWarningBucketNone
}
- if effectiveExpiry > 0 && effectiveExpiry <= now {
- return storageWarningBucketExpired
- }
if effectiveExpiry > now && totalUsage > (allottedStorage+storageWarningOverageThreshold) {
return storageWarningBucketActiveOverage
}
+ if expiredWarningAnchor > 0 && expiredWarningAnchor <= now {
+ return storageWarningBucketExpired
+ }
return storageWarningBucketNone
}
diff --git a/server/pkg/controller/email/storage_warning_expired.go b/server/pkg/controller/email/storage_warning_expired.go
index f0b1a90478..f058b4ef3f 100644
--- a/server/pkg/controller/email/storage_warning_expired.go
+++ b/server/pkg/controller/email/storage_warning_expired.go
@@ -5,10 +5,11 @@ import "github.com/ente-io/museum/pkg/utils/time"
const (
storageWarningExpiredTemplate = "storage_warning_expired.html"
+ storageWarningExpiredAnchorDelay = 30 * 24 * time.MicroSecondsInOneHour
storageWarningExpiredDeletionDelay = 120 * 24 * time.MicroSecondsInOneHour
+ storageWarningExpiredWarning0Delay = 0
storageWarningExpiredWarning30Delay = 30 * 24 * time.MicroSecondsInOneHour
storageWarningExpiredWarning60Delay = 60 * 24 * time.MicroSecondsInOneHour
- storageWarningExpiredWarning90Delay = 90 * 24 * time.MicroSecondsInOneHour
storageWarningExpiredWarning119Delay = 119 * 24 * time.MicroSecondsInOneHour
storageWarningExpired30TemplateID = "storage_warning_expired_30d"
@@ -18,7 +19,7 @@ const (
storageWarningExpired30Subject = "Action needed: Your Ente subscription has expired"
storageWarningExpired60Subject = "Reminder: Your Ente data is scheduled for deletion"
- storageWarningExpired90Subject = "30-day reminder: Your Ente data will be deleted in 30 days"
+ storageWarningExpired90Subject = "Reminder: Renew your Ente plan to avoid data deletion"
storageWarningExpired119Subject = "Final reminder: Your Ente data will be deleted tomorrow"
)
@@ -56,35 +57,44 @@ func expiredWarningTemplateIDs() []string {
}
}
-func resolveExpiredWarningStage(effectiveExpiry int64, now int64, history map[string]int64) expiredWarningStage {
- if effectiveExpiry <= 0 || effectiveExpiry > now {
+// Template IDs are legacy names; the anchored schedule is 0/30/60/119 days from the
+// expired-warning anchor, which is raw subscription expiry + 30 days.
+func resolveExpiredWarningStage(expiredWarningAnchor int64, now int64, history map[string]int64) expiredWarningStage {
+ if expiredWarningAnchor <= 0 || expiredWarningAnchor > now {
return expiredWarningStageNone
}
- daysSinceExpiry := now - effectiveExpiry
- if daysSinceExpiry >= storageWarningExpiredWarning30Delay &&
- !storageWarningTemplateSentInCycle(history, storageWarningExpired30TemplateID, effectiveExpiry) {
+ daysSinceAnchor := now - expiredWarningAnchor
+ if daysSinceAnchor >= storageWarningExpiredWarning0Delay &&
+ !storageWarningTemplateSentInCycle(history, storageWarningExpired30TemplateID, expiredWarningAnchor) {
return expiredWarningStage30
}
- if daysSinceExpiry >= storageWarningExpiredWarning60Delay &&
- !storageWarningTemplateSentInCycle(history, storageWarningExpired60TemplateID, effectiveExpiry) {
+ if daysSinceAnchor >= storageWarningExpiredWarning30Delay &&
+ !storageWarningTemplateSentInCycle(history, storageWarningExpired60TemplateID, expiredWarningAnchor) {
return expiredWarningStage60
}
- if daysSinceExpiry >= storageWarningExpiredWarning90Delay &&
- !storageWarningTemplateSentInCycle(history, storageWarningExpired90TemplateID, effectiveExpiry) {
+ if daysSinceAnchor >= storageWarningExpiredWarning60Delay &&
+ !storageWarningTemplateSentInCycle(history, storageWarningExpired90TemplateID, expiredWarningAnchor) {
return expiredWarningStage90
}
- if daysSinceExpiry >= storageWarningExpiredWarning119Delay &&
- !storageWarningTemplateSentInCycle(history, storageWarningExpired119TemplateID, effectiveExpiry) {
+ if daysSinceAnchor >= storageWarningExpiredWarning119Delay &&
+ !storageWarningTemplateSentInCycle(history, storageWarningExpired119TemplateID, expiredWarningAnchor) {
return expiredWarningStage119
}
return expiredWarningStageNone
}
-func expiredWarningAutoDeleteDate(effectiveExpiry int64, stage expiredWarningStage, now int64) int64 {
- autoDeleteDate := effectiveExpiry + storageWarningExpiredDeletionDelay
+func expiredWarningAutoDeleteDate(expiredWarningAnchor int64, stage expiredWarningStage, now int64) int64 {
+ autoDeleteDate := expiredWarningAnchor + storageWarningExpiredDeletionDelay
if stage == expiredWarningStage119 && autoDeleteDate <= now {
return now + storageWarningOneDayInMicroseconds
}
return autoDeleteDate
}
+
+func expiredWarningAnchorFromSubscriptionExpiry(subscriptionExpiry int64) int64 {
+ if subscriptionExpiry <= 0 {
+ return 0
+ }
+ return subscriptionExpiry + storageWarningExpiredAnchorDelay
+}
diff --git a/server/pkg/controller/email/storage_warning_test.go b/server/pkg/controller/email/storage_warning_test.go
index 84f3185590..8c08cf5e14 100644
--- a/server/pkg/controller/email/storage_warning_test.go
+++ b/server/pkg/controller/email/storage_warning_test.go
@@ -16,32 +16,46 @@ import (
func TestBucketStorageWarningActiveOverage(t *testing.T) {
now := int64(100)
effectiveExpiry := now + 10
+ expiredWarningAnchor := now + 20
allottedStorage := int64(50)
totalUsage := allottedStorage + storageWarningOverageThreshold + 1
- got := bucketStorageWarning(totalUsage, allottedStorage, effectiveExpiry, now)
+ got := bucketStorageWarning(totalUsage, allottedStorage, effectiveExpiry, expiredWarningAnchor, now)
if got != storageWarningBucketActiveOverage {
t.Fatalf("unexpected bucket: got %q want %q", got, storageWarningBucketActiveOverage)
}
}
func TestBucketStorageWarningExpired(t *testing.T) {
- effectiveExpiry := int64(100)
- now := effectiveExpiry
+ effectiveExpiry := int64(90)
+ expiredWarningAnchor := int64(100)
+ now := expiredWarningAnchor
allottedStorage := int64(0)
totalUsage := allottedStorage + storageWarningOverageThreshold + 1
- got := bucketStorageWarning(totalUsage, allottedStorage, effectiveExpiry, now)
+ got := bucketStorageWarning(totalUsage, allottedStorage, effectiveExpiry, expiredWarningAnchor, now)
if got != storageWarningBucketExpired {
t.Fatalf("unexpected bucket: got %q want %q", got, storageWarningBucketExpired)
}
}
+func TestBucketStorageWarningWaitsForExpiredWarningAnchor(t *testing.T) {
+ effectiveExpiry := int64(100)
+ expiredWarningAnchor := effectiveExpiry + storageWarningExpiredAnchorDelay
+ now := effectiveExpiry
+
+ got := bucketStorageWarning(storageWarningOverageThreshold+1, 0, effectiveExpiry, expiredWarningAnchor, now)
+ if got != storageWarningBucketNone {
+ t.Fatalf("unexpected bucket: got %q want %q", got, storageWarningBucketNone)
+ }
+}
+
func TestBucketStorageWarningExpiredRequiresUsageAboveThreshold(t *testing.T) {
effectiveExpiry := int64(100)
+ expiredWarningAnchor := int64(100)
now := effectiveExpiry
- got := bucketStorageWarning(storageWarningOverageThreshold, 0, effectiveExpiry, now)
+ got := bucketStorageWarning(storageWarningOverageThreshold, 0, effectiveExpiry, expiredWarningAnchor, now)
if got != storageWarningBucketNone {
t.Fatalf("unexpected bucket: got %q want %q", got, storageWarningBucketNone)
}
@@ -61,17 +75,24 @@ func TestComputeStorageWarningMetricsActiveSubscription(t *testing.T) {
if got.BaseStorage != subscription.Storage {
t.Fatalf("unexpected base storage: got %d want %d", got.BaseStorage, subscription.Storage)
}
+ if got.SubscriptionExpiry != subscription.ExpiryTime {
+ t.Fatalf("unexpected subscription expiry: got %d want %d", got.SubscriptionExpiry, subscription.ExpiryTime)
+ }
wantEffectiveExpiry := subscription.ExpiryTime + billing.ProviderToExpiryGracePeriodMap[ente.Stripe]
if got.EffectiveExpiry != wantEffectiveExpiry {
t.Fatalf("unexpected effective expiry: got %d want %d", got.EffectiveExpiry, wantEffectiveExpiry)
}
+ wantExpiredWarningAnchor := subscription.ExpiryTime + storageWarningExpiredAnchorDelay
+ if got.ExpiredWarningAnchor != wantExpiredWarningAnchor {
+ t.Fatalf("unexpected expired warning anchor: got %d want %d", got.ExpiredWarningAnchor, wantExpiredWarningAnchor)
+ }
if got.Bucket != storageWarningBucketActiveOverage {
t.Fatalf("unexpected bucket: got %q want %q", got.Bucket, storageWarningBucketActiveOverage)
}
}
func TestComputeStorageWarningMetricsAddonKeepsAccountActive(t *testing.T) {
- now := int64(1000)
+ now := billing.ProviderToExpiryGracePeriodMap[ente.Stripe] + 1000
subscription := &ente.Subscription{
Storage: 100,
ExpiryTime: now - billing.ProviderToExpiryGracePeriodMap[ente.Stripe] - 1,
@@ -93,9 +114,16 @@ func TestComputeStorageWarningMetricsAddonKeepsAccountActive(t *testing.T) {
if got.BaseStorage != 0 {
t.Fatalf("unexpected base storage for expired subscription: got %d want 0", got.BaseStorage)
}
+ if got.SubscriptionExpiry != subscription.ExpiryTime {
+ t.Fatalf("unexpected subscription expiry: got %d want %d", got.SubscriptionExpiry, subscription.ExpiryTime)
+ }
if got.EffectiveExpiry != now+time.MicroSecondsInOneHour {
t.Fatalf("unexpected effective expiry: got %d want %d", got.EffectiveExpiry, now+time.MicroSecondsInOneHour)
}
+ wantExpiredWarningAnchor := subscription.ExpiryTime + storageWarningExpiredAnchorDelay
+ if got.ExpiredWarningAnchor != wantExpiredWarningAnchor {
+ t.Fatalf("unexpected expired warning anchor: got %d want %d", got.ExpiredWarningAnchor, wantExpiredWarningAnchor)
+ }
if got.Bucket != storageWarningBucketActiveOverage {
t.Fatalf("unexpected bucket: got %q want %q", got.Bucket, storageWarningBucketActiveOverage)
}
@@ -118,6 +146,12 @@ func TestComputeStorageWarningMetricsNilSubscriptionDoesNotCrash(t *testing.T) {
if got.BaseStorage != 0 {
t.Fatalf("unexpected base storage without subscription: got %d want 0", got.BaseStorage)
}
+ if got.SubscriptionExpiry != 0 {
+ t.Fatalf("unexpected subscription expiry without subscription: got %d want 0", got.SubscriptionExpiry)
+ }
+ if got.ExpiredWarningAnchor != 0 {
+ t.Fatalf("unexpected expired warning anchor without subscription: got %d want 0", got.ExpiredWarningAnchor)
+ }
if got.Bucket != storageWarningBucketActiveOverage {
t.Fatalf("unexpected bucket: got %q want %q", got.Bucket, storageWarningBucketActiveOverage)
}
@@ -138,13 +172,16 @@ func TestComputeStorageWarningMetricsFreeSubscriptionCanBeActiveOverage(t *testi
if got.BaseStorage != subscription.Storage {
t.Fatalf("unexpected base storage: got %d want %d", got.BaseStorage, subscription.Storage)
}
+ if got.SubscriptionExpiry != subscription.ExpiryTime {
+ t.Fatalf("unexpected subscription expiry: got %d want %d", got.SubscriptionExpiry, subscription.ExpiryTime)
+ }
if got.Bucket != storageWarningBucketActiveOverage {
t.Fatalf("unexpected bucket: got %q want %q", got.Bucket, storageWarningBucketActiveOverage)
}
}
func TestResolveExpiredWarningStage(t *testing.T) {
- effectiveExpiry := int64(100)
+ expiredWarningAnchor := int64(100)
tests := []struct {
name string
@@ -154,54 +191,54 @@ func TestResolveExpiredWarningStage(t *testing.T) {
}{
{
name: "before first reminder",
- now: effectiveExpiry + storageWarningExpiredWarning30Delay - 1,
+ now: expiredWarningAnchor - 1,
history: map[string]int64{},
want: expiredWarningStageNone,
},
{
- name: "first reminder at 30 days",
- now: effectiveExpiry + storageWarningExpiredWarning30Delay,
+ name: "first reminder at anchor day",
+ now: expiredWarningAnchor,
history: map[string]int64{},
want: expiredWarningStage30,
},
{
name: "second reminder after first sent",
- now: effectiveExpiry + storageWarningExpiredWarning60Delay,
+ now: expiredWarningAnchor + storageWarningExpiredWarning30Delay,
history: map[string]int64{
- storageWarningExpired30TemplateID: effectiveExpiry + storageWarningExpiredWarning30Delay,
+ storageWarningExpired30TemplateID: expiredWarningAnchor,
},
want: expiredWarningStage60,
},
{
name: "third reminder after earlier stages sent",
- now: effectiveExpiry + storageWarningExpiredWarning90Delay,
+ now: expiredWarningAnchor + storageWarningExpiredWarning60Delay,
history: map[string]int64{
- storageWarningExpired30TemplateID: effectiveExpiry + storageWarningExpiredWarning30Delay,
- storageWarningExpired60TemplateID: effectiveExpiry + storageWarningExpiredWarning60Delay,
+ storageWarningExpired30TemplateID: expiredWarningAnchor,
+ storageWarningExpired60TemplateID: expiredWarningAnchor + storageWarningExpiredWarning30Delay,
},
want: expiredWarningStage90,
},
{
name: "final reminder for long expired user",
- now: effectiveExpiry + storageWarningExpiredWarning119Delay + 10,
+ now: expiredWarningAnchor + storageWarningExpiredWarning119Delay + 10,
history: map[string]int64{
- storageWarningExpired30TemplateID: effectiveExpiry + storageWarningExpiredWarning30Delay,
- storageWarningExpired60TemplateID: effectiveExpiry + storageWarningExpiredWarning60Delay,
- storageWarningExpired90TemplateID: effectiveExpiry + storageWarningExpiredWarning90Delay,
+ storageWarningExpired30TemplateID: expiredWarningAnchor,
+ storageWarningExpired60TemplateID: expiredWarningAnchor + storageWarningExpiredWarning30Delay,
+ storageWarningExpired90TemplateID: expiredWarningAnchor + storageWarningExpiredWarning60Delay,
},
want: expiredWarningStage119,
},
{
name: "long expired backfill without history starts at first reminder",
- now: effectiveExpiry + storageWarningExpiredWarning119Delay + 10,
+ now: expiredWarningAnchor + storageWarningExpiredWarning119Delay + 10,
history: map[string]int64{},
want: expiredWarningStage30,
},
{
name: "old cycle reminder ignored after renewal",
- now: effectiveExpiry + storageWarningExpiredWarning30Delay,
+ now: expiredWarningAnchor,
history: map[string]int64{
- storageWarningExpired30TemplateID: effectiveExpiry - 1,
+ storageWarningExpired30TemplateID: expiredWarningAnchor - 1,
},
want: expiredWarningStage30,
},
@@ -209,7 +246,7 @@ func TestResolveExpiredWarningStage(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
- got := resolveExpiredWarningStage(effectiveExpiry, tc.now, tc.history)
+ got := resolveExpiredWarningStage(expiredWarningAnchor, tc.now, tc.history)
if got != tc.want {
t.Fatalf("unexpected stage: got %q want %q", got, tc.want)
}
@@ -219,9 +256,9 @@ func TestResolveExpiredWarningStage(t *testing.T) {
func TestExpiredWarningAutoDeleteDateClampsOverdueFinalStage(t *testing.T) {
now := int64(1000)
- effectiveExpiry := now - storageWarningExpiredDeletionDelay - 10
+ expiredWarningAnchor := now - storageWarningExpiredDeletionDelay - 10
- got := expiredWarningAutoDeleteDate(effectiveExpiry, expiredWarningStage119, now)
+ got := expiredWarningAutoDeleteDate(expiredWarningAnchor, expiredWarningStage119, now)
want := now + storageWarningOneDayInMicroseconds
if got != want {
t.Fatalf("unexpected auto delete date: got %d want %d", got, want)
@@ -391,10 +428,10 @@ func TestStorageWarningCadenceBroken(t *testing.T) {
Bucket: storageWarningBucketExpired,
ExpiredStage: expiredWarningStage60,
EvaluatedAt: now,
- EffectiveExpiry: now - storageWarningExpiredWarning60Delay,
- WarningCycleStart: now - storageWarningExpiredWarning60Delay,
+ EffectiveExpiry: now - storageWarningExpiredWarning30Delay,
+ WarningCycleStart: now - storageWarningExpiredWarning30Delay,
NotificationHistory: map[string]int64{
- storageWarningExpired30TemplateID: now - storageWarningExpiredWarning60Delay - 1,
+ storageWarningExpired30TemplateID: now - storageWarningExpiredWarning30Delay - 1,
},
},
wantBroken: true,
@@ -406,8 +443,8 @@ func TestStorageWarningCadenceBroken(t *testing.T) {
Bucket: storageWarningBucketExpired,
ExpiredStage: expiredWarningStage90,
EvaluatedAt: now,
- EffectiveExpiry: now - storageWarningExpiredWarning90Delay,
- WarningCycleStart: now - storageWarningExpiredWarning90Delay,
+ EffectiveExpiry: now - storageWarningExpiredWarning60Delay,
+ WarningCycleStart: now - storageWarningExpiredWarning60Delay,
NotificationHistory: map[string]int64{
storageWarningExpired60TemplateID: now - storageWarningOneDayInMicroseconds,
},