Skip to content

Commit 5dc8ce0

Browse files
jesterhazyyangaws
authored andcommitted
fix flaky tests by using raw regex and run pylint concurrently (#530)
1 parent 15b1be7 commit 5dc8ce0

File tree

9 files changed

+299
-265
lines changed

9 files changed

+299
-265
lines changed

src/sagemaker/fw_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,11 @@ def framework_name_from_image(image_name):
219219
else:
220220
# extract framework, python version and image tag
221221
# We must support both the legacy and current image name format.
222-
name_pattern = \
223-
re.compile('^sagemaker(?:-rl)?-(tensorflow|mxnet|chainer|pytorch|scikit-learn):(.*)-(.*?)-(py2|py3)$')
224-
legacy_name_pattern = re.compile('^sagemaker-(tensorflow|mxnet)-(py2|py3)-(cpu|gpu):(.*)$')
222+
name_pattern = re.compile(
223+
r'^sagemaker(?:-rl)?-(tensorflow|mxnet|chainer|pytorch|scikit-learn):(.*)-(.*?)-(py2|py3)$')
224+
legacy_name_pattern = re.compile(
225+
r'^sagemaker-(tensorflow|mxnet)-(py2|py3)-(cpu|gpu):(.*)$')
226+
225227
name_match = name_pattern.match(sagemaker_match.group(8))
226228
legacy_match = legacy_name_pattern.match(sagemaker_match.group(8))
227229

src/sagemaker/tensorflow/serving.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from __future__ import absolute_import
1414

1515
import logging
16-
1716
import sagemaker
1817
from sagemaker.content_types import CONTENT_TYPE_JSON
1918
from sagemaker.fw_utils import create_image_uri
@@ -144,7 +143,6 @@ def _get_image_uri(self, instance_type):
144143
if self.image:
145144
return self.image
146145

147-
# reuse standard image uri function, then strip unwanted python component
148146
region_name = self.sagemaker_session.boto_region_name
149147
return create_image_uri(region_name, Model.FRAMEWORK_NAME, instance_type,
150148
self._framework_version)

src/sagemaker/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import errno
1616
import os
17+
import random
1718
import re
1819
import sys
1920
import tarfile
@@ -64,6 +65,14 @@ def name_from_base(base, max_length=63, short=False):
6465
return '{}-{}'.format(trimmed_base, timestamp)
6566

6667

68+
def unique_name_from_base(base, max_length=63):
69+
unique = '%04x' % random.randrange(16**4) # 4-digit hex
70+
ts = str(int(time.time()))
71+
available_length = max_length - 2 - len(ts) - len(unique)
72+
trimmed = base[:available_length]
73+
return '{}-{}-{}'.format(trimmed, ts, unique)
74+
75+
6776
def airflow_name_from_base(base, max_length=63, short=False):
6877
"""Append airflow execution_date macro (https://airflow.apache.org/code.html?#macros)
6978
to the provided string. The macro will beevaluated in Airflow operator runtime.

tests/integ/local_mode_utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
from __future__ import absolute_import
14+
15+
import fcntl
16+
import os
17+
import time
18+
from contextlib import contextmanager
19+
20+
import tests.integ
21+
22+
LOCK_PATH = os.path.join(tests.integ.DATA_DIR, 'local_mode_lock')
23+
24+
25+
@contextmanager
26+
def lock():
27+
# Since Local Mode uses the same port for serving, we need a lock in order
28+
# to allow concurrent test execution.
29+
local_mode_lock_fd = open(LOCK_PATH, 'w')
30+
local_mode_lock = local_mode_lock_fd.fileno()
31+
32+
fcntl.lockf(local_mode_lock, fcntl.LOCK_EX)
33+
34+
try:
35+
yield
36+
finally:
37+
time.sleep(5)
38+
fcntl.lockf(local_mode_lock, fcntl.LOCK_UN)

0 commit comments

Comments
 (0)