[ https://issues.apache.org/jira/browse/BEAM-3946?focusedWorklogId=87734&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-87734 ]
ASF GitHub Bot logged work on BEAM-3946: ---------------------------------------- Author: ASF GitHub Bot Created on: 04/Apr/18 19:23 Start Date: 04/Apr/18 19:23 Worklog Time Spent: 10m Work Description: aaltay closed pull request #5021: [BEAM-3946] Fix pubsub_matcher_test which depends on GOOGLE_APPLICATION_CREDENTIALS URL: https://github.com/apache/beam/pull/5021 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher.py b/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher.py index 1fb712fbf67..695bfcd70f6 100644 --- a/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher.py +++ b/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher.py @@ -73,14 +73,14 @@ def __init__(self, project, sub_name, expected_msg, timeout=DEFAULT_TIMEOUT): def _matches(self, _): if self.messages is None: - subscription = (pubsub - .Client(project=self.project) - .subscription(self.sub_name)) - self.messages = self._wait_for_messages(subscription, + self.messages = self._wait_for_messages(self._get_subscription(), len(self.expected_msg), self.timeout) return Counter(self.messages) == Counter(self.expected_msg) + def _get_subscription(self): + return pubsub.Client(project=self.project).subscription(self.sub_name) + def _wait_for_messages(self, subscription, expected_num, timeout): """Wait for messages from given subscription.""" logging.debug('Start pulling messages from %s', subscription.full_name) diff --git a/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher_test.py b/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher_test.py index a7fd310c7dd..6bb780cb714 100644 --- a/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher_test.py +++ b/sdks/python/apache_beam/io/gcp/tests/pubsub_matcher_test.py @@ -44,10 +44,11 @@ def setUp(self): ['mock_expected_msg']) @mock.patch('time.sleep', return_value=None) - @mock.patch('google.cloud.pubsub.Client.subscription') - def test_message_matcher_success(self, mock_sub_cls, unsued_mock): + @mock.patch('apache_beam.io.gcp.tests.pubsub_matcher.' + 'PubSubMessageMatcher._get_subscription') + def test_message_matcher_success(self, mock_get_sub, unsued_mock): self.pubsub_matcher.expected_msg = ['a', 'b'] - mock_sub = mock_sub_cls.return_value + mock_sub = mock_get_sub.return_value mock_sub.pull.side_effect = [ [(1, pubsub.message.Message(b'a', 'unused_id'))], [(2, pubsub.message.Message(b'b', 'unused_id'))], @@ -56,10 +57,11 @@ def test_message_matcher_success(self, mock_sub_cls, unsued_mock): self.assertEqual(mock_sub.pull.call_count, 2) @mock.patch('time.sleep', return_value=None) - @mock.patch('google.cloud.pubsub.Client.subscription') - def test_message_matcher_mismatch(self, mock_sub_cls, unused_mock): + @mock.patch('apache_beam.io.gcp.tests.pubsub_matcher.' + 'PubSubMessageMatcher._get_subscription') + def test_message_matcher_mismatch(self, mock_get_sub, unused_mock): self.pubsub_matcher.expected_msg = ['a'] - mock_sub = mock_sub_cls.return_value + mock_sub = mock_get_sub.return_value mock_sub.pull.return_value = [ (1, pubsub.message.Message(b'c', 'unused_id')), (1, pubsub.message.Message(b'd', 'unused_id')), @@ -73,9 +75,10 @@ def test_message_matcher_mismatch(self, mock_sub_cls, unused_mock): in str(error.exception.args[0])) @mock.patch('time.sleep', return_value=None) - @mock.patch('google.cloud.pubsub.Client.subscription') - def test_message_metcher_timeout(self, mock_sub_cls, unused_mock): - mock_sub = mock_sub_cls.return_value + @mock.patch('apache_beam.io.gcp.tests.pubsub_matcher.' + 'PubSubMessageMatcher._get_subscription') + def test_message_metcher_timeout(self, mock_get_sub, unused_mock): + mock_sub = mock_get_sub.return_value mock_sub.return_value.full_name.return_value = 'mock_sub' self.pubsub_matcher.timeout = 0.1 with self.assertRaises(AssertionError) as error: ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 87734) Time Spent: 20m (was: 10m) > Python SDK tests are failing if no GOOGLE_APPLICATION_CREDENTIALS was set > ------------------------------------------------------------------------- > > Key: BEAM-3946 > URL: https://issues.apache.org/jira/browse/BEAM-3946 > Project: Beam > Issue Type: Bug > Components: examples-python > Reporter: Alexey Romanenko > Assignee: Mark Liu > Priority: Major > Time Spent: 20m > Remaining Estimate: 0h > > Running locally mvn clean install fails on following Apache Beam :: SDKs :: > Python tests: > {{ERROR: test_message_matcher_mismatch > (apache_beam.io.gcp.tests.pubsub_matcher_test.PubSubMatcherTest)}} > {{ERROR: test_message_matcher_success > (apache_beam.io.gcp.tests.pubsub_matcher_test.PubSubMatcherTest)}} > {{ERROR: test_message_metcher_timeout > (apache_beam.io.gcp.tests.pubsub_matcher_test.PubSubMatcherTest)}} > > with an error: > DefaultCredentialsError: Could not automatically determine credentials. > Please set GOOGLE_APPLICATION_CREDENTIALS or > explicitly create credential and re-run the application. For more > information, please see > > [https://developers.google.com/accounts/docs/application-default-credentials]. > -------------------- >> begin captured logging << -------------------- > google.auth.transport._http_client: DEBUG: Making request: GET > [http://169.254.169.254|http://169.254.169.254/] > google.auth.compute_engine._metadata: INFO: Compute Engine Metadata server > unavailable. > --------------------- >> end captured logging << --------------------- > > It looks like it's a regression and it was caused by this commit: > [301853647f2c726c04c5bdb02cab6ff6b39f09d0|https://github.com/apache/beam/commit/301853647f2c726c04c5bdb02cab6ff6b39f09d0] -- This message was sent by Atlassian JIRA (v7.6.3#76005)