Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Fixes #1598 and #1601 - ability to stop tasks gracefully #1604

Merged
merged 1 commit into from
Apr 13, 2017

Conversation

rashmigottipati
Copy link
Contributor

Fixes #1598 and #1601

Summary of changes:

  • Plugins are unsubscribed by the event handler after the task state is Stopped
  • Increment hitCount after the workflow finishes executing
  • TaskStoppedEvent is emitted after the task state is Stopped

Testing done:

  • manual test using mock
  • legacy tests

@intelsdi-x/snap-maintainers

time.Sleep(dur)
}
}

Copy link
Contributor

@IzabellaRaulin IzabellaRaulin Apr 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rashmigottipati, I know that introducing time_to_wait in snap-plugin-collector-mock2 was really helpful for testing gracefully shutdown behavior during working on it. However, I have a doubt about landing this change on master - is it really needed? Does it provide some value - I mean is there any large test which runs mock2 collector and testing this behavior? If yes, that is fine - I won't insist on removing that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IzabellaRaulin thanks for testing it. I agree with you - I don't think it's necessary to land this change on master. I added another test in scheduler_test.go which has timeToWait in collect method and an assertion on the total elapsed time. In my opinion, it would suffice to land this test on master.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove this don't forget to remove the example task that was addded too.

time.Sleep(50 * time.Millisecond)
So(t.State(), ShouldResemble, core.TaskStopped)
c.timeToWait = 0
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rashmigottipati , I have doubt about this test. I will try to propose something another instead of doing that in this way. I will let you know when I have sth.

@IzabellaRaulin
Copy link
Contributor

Besides comments above, general code LGTM

@rashmigottipati rashmigottipati force-pushed the rg/sdi2303 branch 2 times, most recently from ade1e95 to 7c4a900 Compare April 13, 2017 20:31
@rashmigottipati
Copy link
Contributor Author

I deleted the mock test example and changed the medium test to listen on TaskStoppedEvent instead of using time.Sleep().
@jcooklin @IzabellaRaulin

select {
case <-lse.TaskStoppedEvents:
So(time.Since(startTime), ShouldBeGreaterThan, c.timeToWait)
//elapsed time should be greater than 500ms
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(small suggestion) This comment in line 402 should be above the code in line 401

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar suggestions for the following lines 398 & 397, 391 & 390

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed them.

@rashmigottipati rashmigottipati force-pushed the rg/sdi2303 branch 3 times, most recently from bfbb8e2 to b8e37bb Compare April 13, 2017 21:01
@@ -54,6 +55,7 @@ func (m *mockMetricManager) CollectMetrics(string, map[string]map[string]string)
}

func (m *mockMetricManager) PublishMetrics([]core.Metric, map[string]ctypes.ConfigValue, string, string, int) []error {
time.Sleep(m.timeToWait)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even that is only for testing purpose, I suggest moving this time.Sleep() to CollectMetrics rather than having that in the last step in the workflow which is PublishMetrics. The another reason is that collection normally takes longer than publishing, what seems to be more accurate to reality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intended to add this to CollectMetrics. Thanks for pointing it out. Fixed it.

// the last scheduled workflow execution should be allowed to finish
// so we expect that stopping the task is going to happen not early than 500ms (set by by timeToWait)
//the task should have fired once
So(t.HitCount(), ShouldEqual, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move checking the hitCount into the case <-lse.TaskStoppedEvents after the checking that task is Stopped (so the HitCount for 100% sure does not change)

Copy link
Contributor

@IzabellaRaulin IzabellaRaulin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@jcooklin jcooklin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rashmigottipati rashmigottipati merged commit 73bca4a into intelsdi-x:master Apr 13, 2017
@rashmigottipati rashmigottipati deleted the rg/sdi2303 branch April 13, 2017 23:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants