-
Notifications
You must be signed in to change notification settings - Fork 549
Conversation
johnflavin
commented
Dec 2, 2016
- Add event fields from docker updates
- Document the version each had been added
- Deprecate older fields
- Update event tests to assert on new fields
- Refactor event tests (now explicitly test event streaming and polling modes)
Current coverage is 47.79% (diff: 72.97%)
|
Looks like two event tests still fail on Docker 1.9.1. https://travis-ci.org/spotify/docker-client/jobs/186413456 |
I fixed the tests for 1.9. Current build fails on 1.10, but it looks like a random, transient failure. Unrelated to my updates. |
@johnflavin Thanks for the PR. I think the 1.10.3 build keeps failing for some reason though. |
Yes, that does look like a real failure. I spun up a 1.10.3 docker-machine vm, but I wasn't able to reproduce this. I added assertions to the test that the stream does have events so that, at the very least, the test can If this continues to happen on the travis machines, I do have a suspicion about the cause. In the past I have had issues with docker events not behaving like I expected; the cause turned out to be an mismatch between the clocks on the docker vm and the host machine (see moby/moby#25579 for more). I'm not sure if that is happening on the travis machines, but that is where I would investigate. |
Hey, all green! ✅ |
return new EventsFilterParam(name, value); | ||
} | ||
|
||
/** | ||
* Show only certain events. For example, "event=pull" for image pull events. | ||
* @param event Type of event to show | ||
* @return EventsParam | ||
* @since API 1.21 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs here imply this was available since 1.18? https://docs.docker.com/engine/reference/api/docker_remote_api_v1.18/#/monitor-dockers-events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think you are correct. Can fix.
/** | ||
* Valid event types for EventsParam.type | ||
*/ | ||
public enum EventType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also test this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me think this through. I'm not sure exactly what you’re asking to test.
Do you mean we should test whether the filter=type=<>
param works correctly, and that if we ask for, say, only image events, then that's all we get back? That's doable. A test could do a bunch of stuff—pull an image, create a container, create a volume, etc.—then ask docker for the different types of events one-by-one, and verify that we only get back what we expect.
Or do you mean to test the validity of the enum
itself, that it has all the values that it needs to have? I don't know how that would be tested. I'm kind of trusting that the API fully documents all the valid values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. That might take a little time, but it shouldn't be too complicated.
|
||
public static class Actor { | ||
@JsonProperty("ID") private String id; | ||
@JsonProperty("Attributes") private ImmutableMap<String, Object> attributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this just be ImmutableMap<String, String>
or do we expect nested JSON objects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it can be <String, String>
. I'm not sure why I thought it was possible to get an Object
there, but their swagger.yaml says Attributes
will always have String
values.
I'll fix that.
Nice. What changed to make it pass? |
Short answer: nothing. I'm pretty sure that event errors like that, where for some reason docker just doesn't give back events, are machine-dependent and not always reproducible. Like I said in my comment above it could very well be that the clock on the particular docker vm that they were using is out of sync with the host clock. Docker re-syncs occasionally, but in my experience it doesn't happen reliably and I have to manually sync to make the errors stop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnflavin Thanks for adding the extra test. I had a few questions.
.build(); | ||
|
||
// Wait once to clean our event "palette" of events from other tests | ||
Thread.sleep(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably fine for now, but is there a way to check there are no leftover events? Perhaps we can use awaitility in the future here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could do that. There is a case to avoid: when you are streaming events, if you ask for the next one and there is none, the thread will hang while it waits for more to come over the stream. But I can careful in my tests to only assert that there are no events when I have polled for events and the stream is already closed. Also, setting timeouts on the tests will help.
final ContainerCreation container = sut.createContainer(config, containerName); | ||
final String containerId = container.id(); | ||
sut.startContainer(containerId); | ||
Thread.sleep(1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this to wait for the container to exit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct. Writing these tests, I got into problems when I tried to remove a container that was still running. I also tried to stop the container first, but sometimes it was stopped already so that caused its own problems.
assertThat(pullEvent.time(), notNullValue()); | ||
if (dockerApiVersionAtLeast("1.22")) { | ||
assertEquals("image", pullEvent.type()); | ||
assertEquals(IMAGE.getName(), pullEvent.type()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps make this method take more parameters like containerEventAssertions()
below so we don't have to hard-code IMAGE
and BUSYBOX_LATEST
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left the IMAGE.getName()
hard-coded. The method is a helper for assertions about image events only, so they will always have that event.type()
. But I generalized the image name and the type of action.
I just had a thought based on your comment. Currently the event type enum is in It seems it would make more sense to move Maybe I'll give that a go and see if it works. |
👆 ✅ |
Ugh. I just realized that the best version of the |
Test failure appears to be a travis hiccup, unrelated to PR. |
@johnflavin I've seen similar spurious pull failures. I usually click the "restart job" button for the individual failed jobs to fix them. |
I don't have that button. Must be a Travis feature that only repo owners get. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @mattnworb if he wants to take a look.
* Explicitly enumerate event types * Deprecate old fields * Update: Add event filters to query params like all other filter types
Oops. Didn't see the approval before I rebased. |
That's OK. Your last commit is straight forward. |
lgtm 👍 thanks! |