Skip to content

Commit

Permalink
Merge pull request #165 from insolar/NOISSUE-better-goroutines-control
Browse files Browse the repository at this point in the history
NOISSUE: better goroutines control
  • Loading branch information
megge-dream authored Aug 25, 2020
2 parents 7755995 + 618d780 commit 007faca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions etl/controller/pulsemaintainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ func (c *Controller) pulseMaintainer(ctx context.Context) {
select {
case <-ctx.Done():
return
default:
time.Sleep(time.Second * time.Duration(c.cfg.PulsePeriod))
case <-time.After(time.Second * time.Duration(c.cfg.PulsePeriod)):
eraseJetDropRegister(ctx, c, log)
}
eraseJetDropRegister(ctx, c, log)
}
}

Expand Down Expand Up @@ -82,8 +81,7 @@ func (c *Controller) pulseSequence(ctx context.Context) {
select {
case <-ctx.Done():
return
default:
time.Sleep(time.Second * time.Duration(c.cfg.SequentialPeriod))
case <-time.After(time.Second * time.Duration(c.cfg.SequentialPeriod)):
}
var err error
var nextSequential models.Pulse
Expand Down
8 changes: 4 additions & 4 deletions etl/controller/pulsemaintainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func TestController_pulseSequence_Start_NoMissedData(t *testing.T) {
}

func TestController_pulseMaintainer_Start_PulsesCompleteAndNot(t *testing.T) {
var cfg = configuration.Controller{PulsePeriod: 0, ReloadPeriod: 10, ReloadCleanPeriod: 1, SequentialPeriod: 0}
var cfg = configuration.Controller{PulsePeriod: 1, ReloadPeriod: 10, ReloadCleanPeriod: 1, SequentialPeriod: 10}

extractor := mock.NewJetDropsExtractorMock(t)

Expand Down Expand Up @@ -289,9 +289,9 @@ func TestController_pulseMaintainer_Start_PulsesCompleteAndNot(t *testing.T) {
// sequential is 1000000, pulses in db: [1000000, 1000020], expect loading data from 1000000 to 1000010
// sequential is 1000000, pulses in db: [1000000, 1000020], expect don't load already loaded data
// wait ReloadPeriod seconds
// sequential is 1000000, pulses in db: [1000000, 1000020], expect loading data from 1000000 to 1000020
// sequential is 1000000, pulses in db: [1000000, 1000020], expect loading data from 1000000 to 1000010
func TestController_pulseSequence_ReloadPeriodExpired(t *testing.T) {
var cfg = configuration.Controller{PulsePeriod: 0, ReloadPeriod: 2, ReloadCleanPeriod: 1, SequentialPeriod: 0}
var cfg = configuration.Controller{PulsePeriod: 0, ReloadPeriod: 2, ReloadCleanPeriod: 1, SequentialPeriod: 1}

extractor := mock.NewJetDropsExtractorMock(t)

Expand All @@ -310,7 +310,7 @@ func TestController_pulseSequence_ReloadPeriodExpired(t *testing.T) {
require.Equal(t, int64(1000000), fromPulseNumber)
require.Equal(t, int64(1000010), toPulseNumber)
if extractor.LoadJetDropsBeforeCounter() > 2 {
require.Fail(t, "LoadJetDrops was called more than once")
require.Fail(t, "LoadJetDrops was called more than twice")
}
wg.Done()
return nil
Expand Down

0 comments on commit 007faca

Please sign in to comment.