Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonblocking events #154

Merged
merged 5 commits into from
Dec 27, 2016
Merged

Nonblocking events #154

merged 5 commits into from
Dec 27, 2016

Conversation

adamdubiel
Copy link
Collaborator

In addition to adding nonblocking handling of events i added:

  • make format and make check that runs same metalinter command as travis.ci
  • bumped Consul version to 0.7.2 to fix random segfaults on Mac
  • fixed race condition detected by go test -race in MarathonerStub
  • fixed race condition in even_hander_test that caused tests to fail randomly (2nd commit)

Bit more about test fixes. I moved web_handler test suite to web_handler_test and it tests only web_handler, the event queue is stubbed. event_handler tests on the other hand no longer start web_handler, instead events that should be processed are sent directly to the event queue. This fixes a non-trivial race condition in tests, where success of test depended on wether request will be processed by web_handler and sent to the queue before test reaches synchronisation point at blocking send to event_handler stopChan.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.0%) to 81.457% when pulling 3607a6b on nonblocking_events into df6a8a7 on master.

Copy link
Contributor

@janisz janisz left a comment

Choose a reason for hiding this comment

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

Good idea to cleanup tests. We will need to extract events queue before we move to SSE. I left some comments. I think we should split this PR into more commits or multiple PRs. One per bullet point you mentioned:

  • make format and make check that runs same metalinter command as travis.ci
  • bumped Consul version to 0.7.2 to fix random segfaults on Mac
  • fixed race condition detected by go test -race in MarathonerStub
  • fixed race condition in even_hander_test that caused tests to fail randomly (2nd commit)
  • Drop events when queue is full

@@ -27,6 +29,13 @@ test: deps $(SOURCES)
PATH=$(CURRENT_DIR)/bin:$(PATH) go test $(PACKAGES) $(TESTARGS)
go vet $(PACKAGES)

gometalint-exists:
@which gometalinter > /dev/null || \
Copy link
Contributor

Choose a reason for hiding this comment

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

We can fallback with gometalinter installation go get -u github.com/alecthomas/gometalinter

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea, but i would rather not have makefile installing dependencies when running build like this. instead we can create new target like install-tools which would do this job, and error message in -exists tasks would point to running make install-tools. So i will leave this as it is for now and we can introduce this additional target along with changing travis.yaml to use Make

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree. You can add it to deps target

@@ -59,4 +68,7 @@ bump:
git add .goxc.json
git commit -m "Bumped version"

format:
go fmt $(PACKAGES)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use goimports here

"github.com/allegro/marathon-consul/apps"
"github.com/allegro/marathon-consul/service"
consulapi "github.com/hashicorp/consul/api"
"sync"
Copy link
Contributor

Choose a reason for hiding this comment

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

We use goimports to group imports. Please move "sync" up.

TasksStub map[apps.AppID][]*apps.Task
leader string
interactionsMu sync.RWMutex
interactions bool
Copy link
Contributor

Choose a reason for hiding this comment

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

How about changing interactions to int and count them. Then we can use atomic functions on it and we do not need mutex.

Copy link
Contributor

Choose a reason for hiding this comment

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

When using atomic struct containing such field must be properly aligned: golang/go#13868

Copy link
Contributor

@janisz janisz Dec 27, 2016

Choose a reason for hiding this comment

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

I don't think it's our case. We don't target to ARM (we can drop support for x86) and we only need uint32

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would rather leave it with mutex for simplicity/readability sake - no need for "smart" code here, this is just test stub (not hot part of code) and from what i see bool is enough. We can add counter when/If we need it.

// then
assertDropped(t, recorder)
// stopChan returned by newEventHandler can be used as a synchronization
// point to wait until previous event has been processed
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should be converted to function comment

@@ -9,6 +9,7 @@ import (
"github.com/allegro/marathon-consul/events"
"github.com/allegro/marathon-consul/metrics"

"errors"
Copy link
Contributor

Choose a reason for hiding this comment

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

goimports

make check runs gometalinter with the same configuration as in CI builds.
make format runs goimports on all project files.
web_handler tests have been moved to separate file and no longer use
event_handler, only queue interactions are checked.
event_handler tests no longer spin web_handler, instead tested events are
pushed directly to event queue.
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.01%) to 81.403% when pulling 9933ee6 on nonblocking_events into df6a8a7 on master.

@adamdubiel
Copy link
Collaborator Author

@janisz i added requested changes: split change into commits and goimports everywhere

@adamdubiel adamdubiel merged commit cc5e0dd into master Dec 27, 2016
@janisz janisz deleted the nonblocking_events branch December 27, 2016 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants