Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff0018cf43 |
@@ -99,21 +99,29 @@ func TestWebhookDBManager_TotalsSurviveReopen(t *testing.T) {
|
|||||||
}, readTargetTotals(t, db))
|
}, readTargetTotals(t, db))
|
||||||
}
|
}
|
||||||
|
|
||||||
// seedExpiredEvents stores count events created at the given time,
|
// TestRetentionReaper_PrunesMoreThanOneBatch verifies that a prune
|
||||||
// each with a delivered delivery to one target and a failed delivery
|
// larger than one transaction's batch removes every expired event with
|
||||||
// to the other, and one attempt for each delivery.
|
// its deliveries and delivery results, keeps the recent event, and
|
||||||
func seedExpiredEvents(
|
// adds what it removed to the event and target totals, so the totals
|
||||||
t *testing.T,
|
// within retention match the rows still stored.
|
||||||
db *gorm.DB,
|
func TestRetentionReaper_PrunesMoreThanOneBatch(t *testing.T) {
|
||||||
webhookID string,
|
t.Parallel()
|
||||||
count int,
|
|
||||||
createdAt time.Time,
|
|
||||||
delivered, failed string,
|
|
||||||
) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
events := make([]database.Event, count)
|
env := setupRetentionTest(t)
|
||||||
deliveries := make([]database.Delivery, 0, 2*count)
|
|
||||||
|
webhookID := createWebhook(t, env.mainDB.DB(), 30)
|
||||||
|
|
||||||
|
db, err := env.mgr.GetDB(webhookID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Every expired event has a delivered delivery to one target and a
|
||||||
|
// failed one to the other, each with one attempt.
|
||||||
|
expired := database.ExportReapBatchSize + 1
|
||||||
|
delivered, failed := uuid.New().String(), uuid.New().String()
|
||||||
|
old := time.Now().Add(-40 * 24 * time.Hour)
|
||||||
|
|
||||||
|
events := make([]database.Event, expired)
|
||||||
|
deliveries := make([]database.Delivery, 0, 2*expired)
|
||||||
|
|
||||||
for i := range events {
|
for i := range events {
|
||||||
events[i] = database.Event{
|
events[i] = database.Event{
|
||||||
@@ -122,7 +130,7 @@ func seedExpiredEvents(
|
|||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
}
|
}
|
||||||
events[i].ID = uuid.New().String()
|
events[i].ID = uuid.New().String()
|
||||||
events[i].CreatedAt = createdAt
|
events[i].CreatedAt = old
|
||||||
|
|
||||||
deliveries = append(deliveries,
|
deliveries = append(deliveries,
|
||||||
database.Delivery{
|
database.Delivery{
|
||||||
@@ -149,27 +157,6 @@ func seedExpiredEvents(
|
|||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, db.CreateInBatches(results, 500).Error)
|
require.NoError(t, db.CreateInBatches(results, 500).Error)
|
||||||
}
|
|
||||||
|
|
||||||
// TestRetentionReaper_PrunesMoreThanOneBatch verifies that a prune
|
|
||||||
// larger than one transaction's batch removes every expired event with
|
|
||||||
// its deliveries and delivery results, keeps the recent event, and
|
|
||||||
// adds what it removed to the event and target totals, so the totals
|
|
||||||
// within retention match the rows still stored.
|
|
||||||
func TestRetentionReaper_PrunesMoreThanOneBatch(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
env := setupRetentionTest(t)
|
|
||||||
|
|
||||||
webhookID := createWebhook(t, env.mainDB.DB(), 30)
|
|
||||||
|
|
||||||
db, err := env.mgr.GetDB(webhookID)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
expired := database.ExportReapBatchSize + 1
|
|
||||||
delivered, failed := uuid.New().String(), uuid.New().String()
|
|
||||||
seedExpiredEvents(t, db, webhookID, expired,
|
|
||||||
time.Now().Add(-40*24*time.Hour), delivered, failed)
|
|
||||||
|
|
||||||
// One recent event, delivered to the first target.
|
// One recent event, delivered to the first target.
|
||||||
recent := seedEventChain(t, db, webhookID, time.Now())
|
recent := seedEventChain(t, db, webhookID, time.Now())
|
||||||
|
|||||||
@@ -88,8 +88,6 @@ func TestHandleProfile_OwnProfile_OK(t *testing.T) {
|
|||||||
h.HandleProfile().ServeHTTP(w, req)
|
h.HandleProfile().ServeHTTP(w, req)
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
assert.Contains(t, w.Body.String(), "Account Information")
|
|
||||||
assert.NotContains(t, w.Body.String(), "Account Type")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHandleProfile_OtherProfile_Forbidden(t *testing.T) {
|
func TestHandleProfile_OtherProfile_Forbidden(t *testing.T) {
|
||||||
|
|||||||
@@ -246,32 +246,6 @@ func statsPane(t *testing.T, page string) string {
|
|||||||
return pane
|
return pane
|
||||||
}
|
}
|
||||||
|
|
||||||
// assertStatsTargets checks, for the history seedStatsHistory builds,
|
|
||||||
// each target's totals and its deliveries finished in the last 24
|
|
||||||
// hours. The first target has three deliveries and the replay, the
|
|
||||||
// second three; the inactive target has none and so no row.
|
|
||||||
func assertStatsTargets(t *testing.T, hist statsHistory) {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
first, second := hist.first, hist.second
|
|
||||||
|
|
||||||
assert.Equal(t, map[string]database.TargetTotals{
|
|
||||||
first: {TargetID: first, Deliveries: 4, Delivered: 1, Failed: 2},
|
|
||||||
second: {
|
|
||||||
TargetID: second, Deliveries: 3, Delivered: 1, Failed: 1,
|
|
||||||
},
|
|
||||||
}, statsTargetTotals(t, hist.webhookDB))
|
|
||||||
|
|
||||||
lastDay, err := handlers.FinishedByTargetForTest(
|
|
||||||
hist.webhookDB, time.Now().Add(-24*time.Hour),
|
|
||||||
)
|
|
||||||
require.NoError(t, err)
|
|
||||||
assert.ElementsMatch(t, []handlers.TargetFinished{
|
|
||||||
{TargetID: first, Delivered: 1, Failed: 1},
|
|
||||||
{TargetID: second, Failed: 1},
|
|
||||||
}, lastDay)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestWebhookStats_EveryFigureAcrossRetentionPrune checks every figure
|
// TestWebhookStats_EveryFigureAcrossRetentionPrune checks every figure
|
||||||
// the statistics pane shows for the history seedStatsHistory builds,
|
// the statistics pane shows for the history seedStatsHistory builds,
|
||||||
// and each target's totals and recent figures, before and after the
|
// and each target's totals and recent figures, before and after the
|
||||||
@@ -317,7 +291,23 @@ func TestWebhookStats_EveryFigureAcrossRetentionPrune(t *testing.T) {
|
|||||||
assert.Equal(t, "50.0%", stats.Last10Minutes.FailurePercent())
|
assert.Equal(t, "50.0%", stats.Last10Minutes.FailurePercent())
|
||||||
assert.Equal(t, "66.7%", stats.Last24Hours.FailurePercent())
|
assert.Equal(t, "66.7%", stats.Last24Hours.FailurePercent())
|
||||||
|
|
||||||
assertStatsTargets(t, hist)
|
// The first target has three deliveries and the replay, the second
|
||||||
|
// three; the inactive target has none and so no row.
|
||||||
|
assert.Equal(t, map[string]database.TargetTotals{
|
||||||
|
first: {TargetID: first, Deliveries: 4, Delivered: 1, Failed: 2},
|
||||||
|
second: {
|
||||||
|
TargetID: second, Deliveries: 3, Delivered: 1, Failed: 1,
|
||||||
|
},
|
||||||
|
}, statsTargetTotals(t, hist.webhookDB))
|
||||||
|
|
||||||
|
lastDay, err := handlers.FinishedByTargetForTest(
|
||||||
|
hist.webhookDB, time.Now().Add(-24*time.Hour),
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.ElementsMatch(t, []handlers.TargetFinished{
|
||||||
|
{TargetID: first, Delivered: 1, Failed: 1},
|
||||||
|
{TargetID: second, Failed: 1},
|
||||||
|
}, lastDay)
|
||||||
|
|
||||||
// Retention removes the oldest event with its three deliveries:
|
// Retention removes the oldest event with its three deliveries:
|
||||||
// the first target's failed one and the pending replay, and the
|
// the first target's failed one and the pending replay, and the
|
||||||
|
|||||||
@@ -41,6 +41,10 @@
|
|||||||
<dt class="w-32 text-sm font-medium text-gray-500">Username</dt>
|
<dt class="w-32 text-sm font-medium text-gray-500">Username</dt>
|
||||||
<dd class="text-sm text-gray-900">{{.User.Username}}</dd>
|
<dd class="text-sm text-gray-900">{{.User.Username}}</dd>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<dt class="w-32 text-sm font-medium text-gray-500">Account Type</dt>
|
||||||
|
<dd class="text-sm text-gray-900">Standard User</dd>
|
||||||
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user