mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-11-10 14:44:04 +08:00
Rename RecordRefused to Refused
This commit is contained in:
1 parent
7250c3d474
commit
4f1f62b0b5
4 files changed
+29
-29
No files matched your search
@@ -110,7 +110,7 @@ func TestServer_Manager_TopicsUnifiedPushGauge(t *testing.T) {
|
||||
// The manager exports how many UnifiedPush topics the node keeps in memory, to watch their memory
|
||||
s := newTestServer(t, newTestConfig(t, ""))
|
||||
s.topicService.SetRateVisitor("upAAAAAAAAAAAA", "", "1.2.3.4")
|
||||
s.topicService.RecordRefused("upBBBBBBBBBBBB")
|
||||
s.topicService.Refused("upBBBBBBBBBBBB")
|
||||
s.execManager()
|
||||
require.Equal(t, float64(2), testutil.ToFloat64(metrics.TopicsUnifiedPush))
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func (s *Server) rateVisitor(t *topic) (*visitor, error) {
|
||||
return newVisitor(s.visitors, ip, u), nil
|
||||
}
|
||||
|
||||
// unifiedPushTopicAbandoned records a refused push to a UnifiedPush topic (see topic.Service.RecordRefused)
|
||||
// unifiedPushTopicAbandoned records a refused push to a UnifiedPush topic (see topic.Service.Refused)
|
||||
// and returns true if the topic had no subscriber activity, on any node, for
|
||||
// unifiedPushAbandonedAfter. Before a yes, it reads the row, which may be fresher than memory; a
|
||||
// failed read is a no, so the publisher retries.
|
||||
@@ -61,7 +61,7 @@ func (s *Server) unifiedPushTopicAbandoned(r *http.Request, t *topic) bool {
|
||||
if !isUnifiedPushTopic(t.ID) {
|
||||
return false
|
||||
}
|
||||
state := s.topicService.RecordRefused(t.ID)
|
||||
state := s.topicService.Refused(t.ID)
|
||||
if state == nil || t.SubscribersCount() > 0 || !topicAbandoned(state) {
|
||||
return false
|
||||
}
|
||||
|
||||
+2
-2
@@ -134,10 +134,10 @@ func (s *Service) Touch(topic string) {
|
||||
s.addPendingNoLock(s.touchNoLock(topic), false)
|
||||
}
|
||||
|
||||
// RecordRefused records a refused push and returns the topic's state. An unknown topic becomes known as
|
||||
// Refused records a refused push and returns the topic's state. An unknown topic becomes known as
|
||||
// first seen now (unless maxRefused are, then it stays unknown); a known one is left alone, since
|
||||
// a push is not subscriber activity.
|
||||
func (s *Service) RecordRefused(topic string) *State {
|
||||
func (s *Service) Refused(topic string) *State {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if _, ok := s.entries[topic]; !ok && s.refused < maxRefused {
|
||||
|
||||
+24
-24
@@ -54,16 +54,16 @@ func startTestService(t *testing.T, store *Store, now func() time.Time) *Service
|
||||
return s
|
||||
}
|
||||
|
||||
func TestService_SetTouchRecordRefused(t *testing.T) {
|
||||
func TestService_SetTouchRefused(t *testing.T) {
|
||||
s, clock := newTestServiceWithClock(t)
|
||||
require.Nil(t, s.State("upA"))
|
||||
|
||||
// A refused push makes the topic known: first seen now, never subscribed, no rate visitor; a
|
||||
// second one changes nothing
|
||||
noted := clock.unix()
|
||||
require.Equal(t, state("upA", noted, 0, "", ""), withoutUpdatedAt(s.RecordRefused("upA")))
|
||||
require.Equal(t, state("upA", noted, 0, "", ""), withoutUpdatedAt(s.Refused("upA")))
|
||||
clock.advance(time.Hour)
|
||||
require.Equal(t, state("upA", noted, 0, "", ""), withoutUpdatedAt(s.RecordRefused("upA")))
|
||||
require.Equal(t, state("upA", noted, 0, "", ""), withoutUpdatedAt(s.Refused("upA")))
|
||||
require.Equal(t, state("upA", noted, 0, "", ""), stateOf(s, "upA"))
|
||||
|
||||
// A subscriber becomes the rate visitor, and counts as subscriber activity; the latest one wins
|
||||
@@ -80,7 +80,7 @@ func TestService_SetTouchRecordRefused(t *testing.T) {
|
||||
|
||||
// A refused push to a known topic changes nothing, however old its subscriber activity
|
||||
clock.advance(48 * time.Hour)
|
||||
s.RecordRefused("upA")
|
||||
s.Refused("upA")
|
||||
require.Equal(t, state("upA", noted, touched, "u_1", "1.2.3.4"), stateOf(s, "upA"))
|
||||
|
||||
// A touch or a subscribe of an unknown topic makes it known, first seen and subscribed now
|
||||
@@ -95,7 +95,7 @@ func TestService_State_ReturnsCopy(t *testing.T) {
|
||||
s, _ := newTestServiceWithClock(t)
|
||||
s.SetRateVisitor("upA", "", "1.2.3.4")
|
||||
s.State("upA").RateVisitorIP = "5.6.7.8"
|
||||
s.RecordRefused("upA").RateVisitorIP = "5.6.7.8"
|
||||
s.Refused("upA").RateVisitorIP = "5.6.7.8"
|
||||
require.Equal(t, "1.2.3.4", s.State("upA").RateVisitorIP)
|
||||
}
|
||||
|
||||
@@ -116,29 +116,29 @@ func TestService_Touch_Throttled(t *testing.T) {
|
||||
// A touch of an unknown topic, or of one known from refused pushes only, is never throttled
|
||||
s.Touch("upB")
|
||||
require.Equal(t, state("upB", clock.unix(), clock.unix(), "", ""), stateOf(s, "upB"))
|
||||
s.RecordRefused("upC")
|
||||
s.Refused("upC")
|
||||
s.Touch("upC")
|
||||
require.Equal(t, clock.unix(), s.State("upC").SubscribedAt)
|
||||
}
|
||||
|
||||
func TestService_RecordRefused_Bounded(t *testing.T) {
|
||||
func TestService_Refused_Bounded(t *testing.T) {
|
||||
// Topics known only from refused pushes are capped; a subscriber frees a slot
|
||||
s, _ := newTestServiceWithClock(t)
|
||||
for i := 0; i < maxRefused; i++ {
|
||||
s.RecordRefused(fmt.Sprintf("up%012d", i))
|
||||
s.Refused(fmt.Sprintf("up%012d", i))
|
||||
}
|
||||
require.Equal(t, maxRefused, s.Size())
|
||||
require.Nil(t, s.RecordRefused("upOneTooMany"))
|
||||
require.Nil(t, s.Refused("upOneTooMany"))
|
||||
require.Nil(t, s.State("upOneTooMany"))
|
||||
s.Touch("up000000000000")
|
||||
require.NotNil(t, s.RecordRefused("upOneTooMany"))
|
||||
require.Nil(t, s.RecordRefused("upTwoTooMany"))
|
||||
require.NotNil(t, s.Refused("upOneTooMany"))
|
||||
require.Nil(t, s.Refused("upTwoTooMany"))
|
||||
}
|
||||
|
||||
func TestService_Prune(t *testing.T) {
|
||||
// Topics are pruned pruneAfter after their last write
|
||||
s, clock := newTestServiceWithClock(t)
|
||||
s.RecordRefused("upA")
|
||||
s.Refused("upA")
|
||||
clock.advance(time.Hour)
|
||||
s.Touch("upB")
|
||||
clock.advance(pruneAfter - 30*time.Minute)
|
||||
@@ -148,12 +148,12 @@ func TestService_Prune(t *testing.T) {
|
||||
|
||||
// A pruned topic may be recorded again
|
||||
for i := 0; i < maxRefused; i++ {
|
||||
s.RecordRefused(fmt.Sprintf("up%012d", i))
|
||||
s.Refused(fmt.Sprintf("up%012d", i))
|
||||
}
|
||||
require.Nil(t, s.RecordRefused("upOneTooMany"))
|
||||
require.Nil(t, s.Refused("upOneTooMany"))
|
||||
clock.advance(pruneAfter + time.Hour)
|
||||
s.prune(clock.unix() - int64(pruneAfter/time.Second))
|
||||
require.NotNil(t, s.RecordRefused("upOneTooMany"))
|
||||
require.NotNil(t, s.Refused("upOneTooMany"))
|
||||
}
|
||||
|
||||
func TestService_Prune_AfterAWeek(t *testing.T) {
|
||||
@@ -196,7 +196,7 @@ func TestService_Persist_SurvivesRestart(t *testing.T) {
|
||||
clock := newTestClock()
|
||||
s := startTestService(t, newStore(), clock.now)
|
||||
s.SetRateVisitor("upA", "", "1.2.3.4")
|
||||
s.RecordRefused("upB")
|
||||
s.Refused("upB")
|
||||
s.Close()
|
||||
s = startTestService(t, newStore(), clock.now)
|
||||
require.Equal(t, state("upA", clock.unix(), clock.unix(), "", "1.2.3.4"), stateOf(s, "upA"))
|
||||
@@ -221,14 +221,14 @@ func TestService_Persist_StartServesIfLoadFails(t *testing.T) {
|
||||
cancel()
|
||||
require.Nil(t, s.Start(ctx))
|
||||
require.Nil(t, s.State("upA"))
|
||||
require.NotNil(t, s.RecordRefused("upB"))
|
||||
require.NotNil(t, s.Refused("upB"))
|
||||
s.sync()
|
||||
require.Equal(t, "1.2.3.4", s.State("upA").RateVisitorIP)
|
||||
require.Equal(t, 2, s.Size())
|
||||
})
|
||||
}
|
||||
|
||||
func TestService_Persist_RecordRefusedDoesNotReviveRateVisitor(t *testing.T) {
|
||||
func TestService_Persist_RefusedDoesNotReviveRateVisitor(t *testing.T) {
|
||||
// A refused push on a node that does not know the topic neither moves its subscriber activity
|
||||
// nor touches its rate visitor on the other nodes: it is insert-only
|
||||
forEachBackend(t, func(t *testing.T, newStore func() *Store) {
|
||||
@@ -239,7 +239,7 @@ func TestService_Persist_RecordRefusedDoesNotReviveRateVisitor(t *testing.T) {
|
||||
set := clock.unix()
|
||||
a.sync()
|
||||
clock.advance(25 * time.Hour)
|
||||
b.RecordRefused("upA") // b has not read a's row yet
|
||||
b.Refused("upA") // b has not read a's row yet
|
||||
b.sync()
|
||||
a.sync()
|
||||
b.sync()
|
||||
@@ -323,7 +323,7 @@ func TestService_Persist_MergesFirstSeenAndSubscribed(t *testing.T) {
|
||||
clock := newTestClock()
|
||||
a := startTestService(t, newStore(), clock.now)
|
||||
b := startTestService(t, newStore(), clock.now)
|
||||
a.RecordRefused("upA")
|
||||
a.Refused("upA")
|
||||
noted := clock.unix()
|
||||
clock.advance(time.Hour)
|
||||
b.Touch("upA")
|
||||
@@ -436,10 +436,10 @@ func TestService_Persist_PrunesTableAndMemory(t *testing.T) {
|
||||
clock := newTestClock()
|
||||
store := newStore()
|
||||
s := startTestService(t, store, clock.now)
|
||||
s.RecordRefused("upA")
|
||||
s.Refused("upA")
|
||||
s.sync()
|
||||
clock.advance(pruneAfter + 2*time.Hour)
|
||||
s.RecordRefused("upB")
|
||||
s.Refused("upB")
|
||||
s.sync() // Prunes: an hour has passed since the last one
|
||||
require.Nil(t, s.State("upA"))
|
||||
require.NotNil(t, s.State("upB"))
|
||||
@@ -464,7 +464,7 @@ func TestService_Persist_PrunesTableAndMemory(t *testing.T) {
|
||||
func TestService_WithoutStore(t *testing.T) {
|
||||
s := New(nil)
|
||||
require.Nil(t, s.Start(context.Background()))
|
||||
s.RecordRefused("upA")
|
||||
s.Refused("upA")
|
||||
topic, err := s.Refresh(context.Background(), "upA")
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, s.State("upA"), topic)
|
||||
@@ -474,7 +474,7 @@ func TestService_WithoutStore(t *testing.T) {
|
||||
func TestService_WithoutStore_NothingWaitsToBeWritten(t *testing.T) {
|
||||
// Without a store nothing is ever written, so nothing may wait to be: pruned topics are gone for good
|
||||
s, clock := newTestServiceWithClock(t)
|
||||
s.RecordRefused("upA")
|
||||
s.Refused("upA")
|
||||
s.Touch("upB")
|
||||
s.SetRateVisitor("upC", "", "1.2.3.4")
|
||||
clock.advance(pruneAfter + time.Hour)
|
||||
|
||||
Reference in new issue
Block a user