This is an automated email from the ASF dual-hosted git repository. asekretenko pushed a commit to branch 1.10.x in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 3ca3879d52ea0f9bff05443d331d63105b2cc4db Author: Andrei Sekretenko <asekrete...@apache.org> AuthorDate: Thu Aug 20 18:36:40 2020 +0200 Added a test for discarding image pull on discard of getting image. This test checks that when all futures returned by docker store's `get()` that are pending image pull are discarded by the callers, the pull future (returned by the puller to the store) is discarded by the store as well. Review: https://reviews.apache.org/r/72794 --- .../containerizer/provisioner_docker_tests.cpp | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/tests/containerizer/provisioner_docker_tests.cpp b/src/tests/containerizer/provisioner_docker_tests.cpp index 5de97e2..b1f38ae 100644 --- a/src/tests/containerizer/provisioner_docker_tests.cpp +++ b/src/tests/containerizer/provisioner_docker_tests.cpp @@ -23,6 +23,7 @@ #include <stout/path.hpp> #include <stout/stringify.hpp> +#include <process/clock.hpp> #include <process/future.hpp> #include <process/gmock.hpp> #include <process/owned.hpp> @@ -59,6 +60,7 @@ namespace spec = ::docker::spec; using std::string; using std::vector; +using process::Clock; using process::Future; using process::Owned; using process::PID; @@ -415,6 +417,49 @@ TEST_F(ProvisionerDockerLocalStoreTest, PullingSameImageSimultaneously) } +// This tests that pulling the image will be cancelled if all the pending +// futures returned by `Store::get()` for this pull are discarded. +TEST_F(ProvisionerDockerLocalStoreTest, PullDiscarded) +{ + slave::Flags flags; + flags.docker_registry = path::join(os::getcwd(), "images"); + flags.docker_store_dir = path::join(os::getcwd(), "store"); + + MockPuller* puller = new MockPuller(); + Future<Nothing> pullCalled; + Promise<slave::docker::Image> promise; + + EXPECT_CALL(*puller, pull(_, _, _, _)) + .WillOnce(testing::DoAll(FutureSatisfy(&pullCalled), + Return(promise.future()))); + + Try<Owned<slave::Store>> store = + slave::docker::Store::create(flags, Owned<Puller>(puller)); + + ASSERT_SOME(store); + + Image mesosImage; + mesosImage.set_type(Image::DOCKER); + mesosImage.mutable_docker()->set_name("abc"); + + Future<slave::ImageInfo> imageInfo1 = + store.get()->get(mesosImage, COPY_BACKEND); + + Future<slave::ImageInfo> imageInfo2 = + store.get()->get(mesosImage, COPY_BACKEND); + + AWAIT_READY(pullCalled); + + imageInfo1.discard(); + imageInfo2.discard(); + + Clock::pause(); + Clock::settle(); + + ASSERT_TRUE(promise.future().hasDiscard()); +} + + #ifdef __linux__ class ProvisionerDockerTest : public MesosTest,