Skip to content

Commit

Permalink
ref: rename hibernation life-cycle events start and stop (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Sep 4, 2024
1 parent 6edd565 commit f25cdf9
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 72 deletions.
36 changes: 18 additions & 18 deletions cycle/event-start_test.go → cycle/event-sleep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
var _ = Describe("event", func() {
var description string

Context("start", func() {
Context("sleep", func() {
Context("single", func() {
When("listener", func() {
It("🧪 should: invoke client's handler", func() {
invoked := false
o, _ := pref.Get()

o.Events.Start.On(func(_ string) {
o.Events.Sleep.On(func(_ string) {
invoked = true
})
o.Binder.Controls.Start.Dispatch()(description)
o.Binder.Controls.Sleep.Dispatch()(description)

Expect(invoked).To(BeTrue())
})
Expand All @@ -31,16 +31,16 @@ var _ = Describe("event", func() {
invoked := false
o, _ := pref.Get()

o.Events.Start.On(func(_ string) {
o.Events.Sleep.On(func(_ string) {
invoked = true
})
o.Binder.Controls.Start.Mute()
o.Binder.Controls.Start.Dispatch()(description)
o.Binder.Controls.Sleep.Mute()
o.Binder.Controls.Sleep.Dispatch()(description)
Expect(invoked).To(BeFalse(), "notification not muted")

invoked = false
o.Binder.Controls.Start.Unmute()
o.Binder.Controls.Start.Dispatch()(description)
o.Binder.Controls.Sleep.Unmute()
o.Binder.Controls.Sleep.Dispatch()(description)
Expect(invoked).To(BeTrue(), "notification not muted")
})
})
Expand All @@ -52,21 +52,21 @@ var _ = Describe("event", func() {
count := 0
o, _ := pref.Get()

o.Events.Start.On(func(_ string) {
o.Events.Sleep.On(func(_ string) {
count++
})
o.Events.Start.On(func(_ string) {
o.Events.Sleep.On(func(_ string) {
count++
})
o.Binder.Controls.Start.Dispatch()(description)
o.Binder.Controls.Sleep.Dispatch()(description)
Expect(count).To(Equal(2), "not all listeners were invoked for first notification")

count = 0
o.Events.Start.On(func(_ string) {
o.Events.Sleep.On(func(_ string) {
count++
})

o.Binder.Controls.Start.Dispatch()(description)
o.Binder.Controls.Sleep.Dispatch()(description)
Expect(count).To(Equal(3), "not all listeners were invoked for second notification")
})
})
Expand All @@ -76,15 +76,15 @@ var _ = Describe("event", func() {
count := 0
o, _ := pref.Get()

o.Events.Start.On(func(_ string) {
o.Events.Sleep.On(func(_ string) {
count++
})
o.Events.Start.On(func(_ string) {
o.Events.Sleep.On(func(_ string) {
count++
})

o.Binder.Controls.Start.Mute()
o.Binder.Controls.Start.Dispatch()(description)
o.Binder.Controls.Sleep.Mute()
o.Binder.Controls.Sleep.Dispatch()(description)

Expect(count).To(Equal(0), "notification not muted")
})
Expand All @@ -95,7 +95,7 @@ var _ = Describe("event", func() {
It("🧪 should: invoke no-op", func() {
o, _ := pref.Get()

o.Binder.Controls.Start.Dispatch()(description)
o.Binder.Controls.Sleep.Dispatch()(description)
})
})
})
Expand Down
36 changes: 18 additions & 18 deletions cycle/event-stop_test.go → cycle/event-wake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import (
var _ = Describe("event", func() {
var description string

Context("stop", func() {
Context("wake", func() {
Context("single", func() {
When("listener", func() {
It("🧪 should: invoke client's handler", func() {
invoked := false
o, _ := pref.Get()

o.Events.Stop.On(func(_ string) {
o.Events.Wake.On(func(_ string) {
invoked = true
})
o.Binder.Controls.Stop.Dispatch()(description)
o.Binder.Controls.Wake.Dispatch()(description)

Expect(invoked).To(BeTrue())
})
Expand All @@ -31,16 +31,16 @@ var _ = Describe("event", func() {
invoked := false
o, _ := pref.Get()

o.Events.Stop.On(func(_ string) {
o.Events.Wake.On(func(_ string) {
invoked = true
})
o.Binder.Controls.Stop.Mute()
o.Binder.Controls.Stop.Dispatch()(description)
o.Binder.Controls.Wake.Mute()
o.Binder.Controls.Wake.Dispatch()(description)
Expect(invoked).To(BeFalse(), "notification not muted")

invoked = false
o.Binder.Controls.Stop.Unmute()
o.Binder.Controls.Stop.Dispatch()(description)
o.Binder.Controls.Wake.Unmute()
o.Binder.Controls.Wake.Dispatch()(description)
Expect(invoked).To(BeTrue(), "notification not muted")
})
})
Expand All @@ -52,21 +52,21 @@ var _ = Describe("event", func() {
count := 0
o, _ := pref.Get()

o.Events.Stop.On(func(_ string) {
o.Events.Wake.On(func(_ string) {
count++
})
o.Events.Stop.On(func(_ string) {
o.Events.Wake.On(func(_ string) {
count++
})
o.Binder.Controls.Stop.Dispatch()(description)
o.Binder.Controls.Wake.Dispatch()(description)
Expect(count).To(Equal(2), "not all listeners were invoked for first notification")

count = 0
o.Events.Stop.On(func(_ string) {
o.Events.Wake.On(func(_ string) {
count++
})

o.Binder.Controls.Stop.Dispatch()(description)
o.Binder.Controls.Wake.Dispatch()(description)
Expect(count).To(Equal(3), "not all listeners were invoked for second notification")
})
})
Expand All @@ -76,15 +76,15 @@ var _ = Describe("event", func() {
count := 0
o, _ := pref.Get()

o.Events.Stop.On(func(_ string) {
o.Events.Wake.On(func(_ string) {
count++
})
o.Events.Stop.On(func(_ string) {
o.Events.Wake.On(func(_ string) {
count++
})

o.Binder.Controls.Stop.Mute()
o.Binder.Controls.Stop.Dispatch()(description)
o.Binder.Controls.Wake.Mute()
o.Binder.Controls.Wake.Dispatch()(description)

Expect(count).To(Equal(0), "notification not muted")
})
Expand All @@ -95,7 +95,7 @@ var _ = Describe("event", func() {
It("🧪 should: invoke no-op", func() {
o, _ := pref.Get()

o.Binder.Controls.Stop.Dispatch()(description)
o.Binder.Controls.Wake.Dispatch()(description)
})
})
})
Expand Down
16 changes: 8 additions & 8 deletions cycle/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type (
Begin Event[BeginHandler]
Descend Event[NodeHandler]
End Event[EndHandler]
Start Event[HibernateHandler]
Stop Event[HibernateHandler]
Wake Event[HibernateHandler]
Sleep Event[HibernateHandler]
}

// since the Controls are only required internally as they are used
Expand All @@ -35,8 +35,8 @@ type (
Begin NotificationCtrl[BeginHandler]
Descend NotificationCtrl[NodeHandler]
End NotificationCtrl[EndHandler]
Start NotificationCtrl[HibernateHandler]
Stop NotificationCtrl[HibernateHandler]
Wake NotificationCtrl[HibernateHandler]
Sleep NotificationCtrl[HibernateHandler]
}
)

Expand All @@ -58,8 +58,8 @@ func NewControls() Controls {
Begin: *NewNotificationCtrl[BeginHandler](nopBegin, broadcastBegin),
Descend: *NewNotificationCtrl[NodeHandler](nopNode, broadcastNode),
End: *NewNotificationCtrl[EndHandler](nopEnd, broadcastEnd),
Start: *NewNotificationCtrl[HibernateHandler](nopHibernate, broadcastHibernate),
Stop: *NewNotificationCtrl[HibernateHandler](nopHibernate, broadcastHibernate),
Wake: *NewNotificationCtrl[HibernateHandler](nopHibernate, broadcastHibernate),
Sleep: *NewNotificationCtrl[HibernateHandler](nopHibernate, broadcastHibernate),
}
}

Expand All @@ -70,8 +70,8 @@ func (e *Events) Bind(cs *Controls) {
e.Begin = &cs.Begin
e.Descend = &cs.Descend
e.End = &cs.End
e.Start = &cs.Start
e.Stop = &cs.Stop
e.Wake = &cs.Wake
e.Sleep = &cs.Sleep
}

// On subscribes to a life cycle event
Expand Down
6 changes: 3 additions & 3 deletions director-prime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var _ = Describe("Director(Prime)", Ordered, func() {
Handler: noOpHandler,
},
tv.WithFilter(&pref.FilterOptions{}),
tv.WithOnStart(func(_ string) {}),
tv.WithOnWake(func(_ string) {}),
)).Navigate(ctx)

Expect(err).To(Succeed())
Expand All @@ -180,7 +180,7 @@ var _ = Describe("Director(Prime)", Ordered, func() {
Type: enums.FilterTypeGlob,
Pattern: "*",
}),
tv.WithOnStop(func(_ string) {}),
tv.WithOnSleep(func(_ string) {}),
)).Navigate(ctx)

Expect(err).To(Succeed())
Expand All @@ -205,7 +205,7 @@ var _ = Describe("Director(Prime)", Ordered, func() {
Type: enums.FilterTypeGlob,
Pattern: "*",
}),
tv.WithOnStop(func(_ string) {}),
tv.WithOnSleep(func(_ string) {}),
)).Navigate(ctx)

Expect(err).To(Succeed())
Expand Down
4 changes: 2 additions & 2 deletions enums/notification-en.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
NotificationEnd // end-notification
NotificationDescend // descend-notification
NotificationAscend // ascend-notification
NotificationStart // start-notification
NotificationStop // stop-notification
NotificationWake // wake-notification
NotificationSleep // sleep-notification
NotificationAll = math.MaxUint32 // all-notification
)
4 changes: 2 additions & 2 deletions internal/feat/hiber/hibernate-simple-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (p *simple) create() hibernateStates {
enums.HibernationPending: state{
next: func(node *core.Node, _ override.Inspection) (bool, error) {
if p.common.triggers.wake.IsMatch(node) {
p.controls.Start.Dispatch()(p.common.triggers.wake.Description())
p.controls.Wake.Dispatch()(p.common.triggers.wake.Description())
p.transition(enums.HibernationActive)

if p.common.ho.Behaviour.InclusiveWake {
Expand All @@ -89,7 +89,7 @@ func (p *simple) create() hibernateStates {
enums.HibernationActive: state{
next: func(node *core.Node, _ override.Inspection) (bool, error) {
if p.common.triggers.sleep.IsMatch(node) {
p.controls.Stop.Dispatch()(p.common.triggers.sleep.Description())
p.controls.Sleep.Dispatch()(p.common.triggers.sleep.Description())
p.transition(enums.HibernationRetired)

if p.common.ho.Behaviour.InclusiveSleep {
Expand Down
18 changes: 9 additions & 9 deletions internal/feat/hiber/hibernate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ var _ = Describe("feature", Ordered, func() {
},
},

tv.WithOnStart(func(description string) {
tv.WithOnWake(func(description string) {
GinkgoWriter.Printf("===> 🔊 Wake: '%v'\n", description)
}),

tv.WithOnStop(func(description string) {
tv.WithOnSleep(func(description string) {
GinkgoWriter.Printf("===> 🔇 Sleep: '%v'\n", description)
}),

Expand Down Expand Up @@ -154,11 +154,11 @@ var _ = Describe("feature", Ordered, func() {
},
},

tv.WithOnStart(func(description string) {
tv.WithOnWake(func(description string) {
GinkgoWriter.Printf("===> 🔊 Wake: '%v'\n", description)
}),

tv.WithOnStop(func(description string) {
tv.WithOnSleep(func(description string) {
GinkgoWriter.Printf("===> 🔇 Sleep: '%v'\n", description)
}),

Expand Down Expand Up @@ -202,7 +202,7 @@ var _ = Describe("feature", Ordered, func() {

Entry(nil, &hibernateTE{
NaviTE: helpers.NaviTE{
Given: "start and stop (folders, inclusive:default)",
Given: "wake and sleep (folders, inclusive:default)",
Relative: "RETRO-WAVE",
Subscription: enums.SubscribeFolders,
Mandatory: []string{"Night Drive", "College",
Expand Down Expand Up @@ -235,7 +235,7 @@ var _ = Describe("feature", Ordered, func() {

Entry(nil, &hibernateTE{
NaviTE: helpers.NaviTE{
Given: "start and stop (folders, excl:start, inc:stop, mute)",
Given: "wake and sleep (folders, excl:wake, inc:sleep, mute)",
Relative: "RETRO-WAVE",
Subscription: enums.SubscribeFolders,
Mandatory: []string{"College", "Northern Council",
Expand Down Expand Up @@ -269,7 +269,7 @@ var _ = Describe("feature", Ordered, func() {

Entry(nil, &hibernateTE{
NaviTE: helpers.NaviTE{
Given: "start only (folders, inclusive:default)",
Given: "wake only (folders, inclusive:default)",
Relative: "RETRO-WAVE",
Subscription: enums.SubscribeFolders,
Mandatory: []string{"Night Drive", "College", "Northern Council",
Expand All @@ -295,7 +295,7 @@ var _ = Describe("feature", Ordered, func() {

Entry(nil, &hibernateTE{
NaviTE: helpers.NaviTE{
Given: "stop only (folders, inclusive:default)",
Given: "sleep only (folders, inclusive:default)",
Relative: "RETRO-WAVE",
Subscription: enums.SubscribeFolders,
Mandatory: []string{"RETRO-WAVE", "Chromatics", "Night Drive", "College",
Expand All @@ -322,7 +322,7 @@ var _ = Describe("feature", Ordered, func() {

Entry(nil, &hibernateTE{
NaviTE: helpers.NaviTE{
Given: "stop only (folders, inclusive:default)",
Given: "sleep only (folders, inclusive:default)",
Relative: "RETRO-WAVE",
Subscription: enums.SubscribeFolders,
Mandatory: []string{"RETRO-WAVE", "Chromatics"},
Expand Down
4 changes: 2 additions & 2 deletions internal/feat/hiber/with-filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ var _ = Describe("feature", Ordered, func() {
return rsys.ReadDir(helpers.TrimRoot(dirname))
},
),
tv.WithOnStart(func(description string) {
tv.WithOnWake(func(description string) {
GinkgoWriter.Printf("===> 🔆 Waking: '%v'\n", description)
}),
tv.WithOnStop(func(description string) {
tv.WithOnSleep(func(description string) {
GinkgoWriter.Printf("===> 🌙 Sleeping: '%v'\n", description)
}),
)).Navigate(ctx)
Expand Down
Loading

0 comments on commit f25cdf9

Please sign in to comment.