github.com/uber/kraken@v0.1.4/test/python/test_replication.py (about)

     1  # Copyright (c) 2016-2019 Uber Technologies, Inc.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  from __future__ import absolute_import
    15  
    16  import time
    17  
    18  import pytest
    19  
    20  from conftest import TEST_IMAGE
    21  
    22  
    23  def test_docker_image_replication_success(one_way_replicas):
    24      one_way_replicas.src.proxy.push(TEST_IMAGE)
    25  
    26      # Wait for replication to finish.
    27      time.sleep(5)
    28  
    29      with one_way_replicas.dst.agent_factory.create() as agent:
    30          agent.pull(TEST_IMAGE)
    31  
    32  
    33  def test_docker_image_replication_retry(one_way_replicas):
    34      for build_index in one_way_replicas.dst.build_indexes:
    35          build_index.stop()
    36  
    37      one_way_replicas.src.proxy.push(TEST_IMAGE)
    38  
    39      time.sleep(2)
    40  
    41      with one_way_replicas.dst.agent_factory.create() as agent:
    42          with pytest.raises(AssertionError):
    43              agent.pull(TEST_IMAGE)
    44  
    45      for build_index in one_way_replicas.dst.build_indexes:
    46          build_index.start()
    47  
    48      time.sleep(2)
    49  
    50      with one_way_replicas.dst.agent_factory.create() as agent:
    51          agent.pull(TEST_IMAGE)
    52  
    53  
    54  def test_docker_image_replication_resilient_to_build_index_data_loss(one_way_replicas):
    55      for build_index in one_way_replicas.dst.build_indexes:
    56          build_index.stop()
    57  
    58      one_way_replicas.src.proxy.push(TEST_IMAGE)
    59  
    60      one_way_replicas.src.build_indexes[0].stop() # Initial replicate was sent to this one.
    61      one_way_replicas.src.build_indexes[1].stop()
    62  
    63      # The replicate task should have been duplicated to the third build-index,
    64      # so once zone2 is available it should replicate the image.
    65  
    66      time.sleep(2)
    67  
    68      with one_way_replicas.dst.agent_factory.create() as agent:
    69          with pytest.raises(AssertionError):
    70              agent.pull(TEST_IMAGE)
    71  
    72      for build_index in one_way_replicas.dst.build_indexes:
    73          build_index.start()
    74  
    75      time.sleep(3)
    76  
    77      with one_way_replicas.dst.agent_factory.create() as agent:
    78          agent.pull(TEST_IMAGE)