tvalentyn commented on code in PR #23507:
URL: https://github.com/apache/beam/pull/23507#discussion_r1004689412


##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')
+
+  @pytest.mark.it_postcommit
+  @pytest.mark.sickbay_direct
+  @pytest.mark.sickbay_spark
+  @pytest.mark.sickbay_flink
+  @pytest.mark.timeout(
+      900)  # Timeout after 15 minutes to give Dataflow some extra time
+  def test_periodicsequence_outputs_valid_watermarks_it(self):
+    """Tests periodic sequence with watermarks on dataflow.
+    For testing that watermarks are being correctly emitted,
+    we make sure that there's not a long gap between an element being
+    emitted and being correctly aggregated.
+    """
+    class DoFnWithLongGaps(DoFn):
+      def process(self, element):
+        now = time.time()
+        if now - element[0] > 25:
+          yield (element[0], now)
+
+    start_time = time.time()
+    # Run long enough for Dataflow to start up
+    duration = 540

Review Comment:
   nit: it's better to add units, e.g. `duration_sec`.



##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')
+
+  @pytest.mark.it_postcommit
+  @pytest.mark.sickbay_direct
+  @pytest.mark.sickbay_spark
+  @pytest.mark.sickbay_flink

Review Comment:
   does this still fail w/ flink?



##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')

Review Comment:
   i don't think runner_name or project are used in this test. It may be a part 
of some boilerplate that is travelling from test to test w/o a reason



##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')
+
+  @pytest.mark.it_postcommit
+  @pytest.mark.sickbay_direct
+  @pytest.mark.sickbay_spark
+  @pytest.mark.sickbay_flink
+  @pytest.mark.timeout(
+      900)  # Timeout after 15 minutes to give Dataflow some extra time

Review Comment:
   I am a little worried about 15 min timeout. Let's double it to be safe, to 
prevent flakiness.



##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')
+
+  @pytest.mark.it_postcommit
+  @pytest.mark.sickbay_direct
+  @pytest.mark.sickbay_spark
+  @pytest.mark.sickbay_flink
+  @pytest.mark.timeout(
+      900)  # Timeout after 15 minutes to give Dataflow some extra time
+  def test_periodicsequence_outputs_valid_watermarks_it(self):
+    """Tests periodic sequence with watermarks on dataflow.
+    For testing that watermarks are being correctly emitted,
+    we make sure that there's not a long gap between an element being
+    emitted and being correctly aggregated.
+    """
+    class DoFnWithLongGaps(DoFn):

Review Comment:
   consider: `FindLongGaps` or `FindLongGapsInProcessing`



##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')
+
+  @pytest.mark.it_postcommit
+  @pytest.mark.sickbay_direct
+  @pytest.mark.sickbay_spark
+  @pytest.mark.sickbay_flink
+  @pytest.mark.timeout(
+      900)  # Timeout after 15 minutes to give Dataflow some extra time
+  def test_periodicsequence_outputs_valid_watermarks_it(self):
+    """Tests periodic sequence with watermarks on dataflow.
+    For testing that watermarks are being correctly emitted,
+    we make sure that there's not a long gap between an element being
+    emitted and being correctly aggregated.
+    """
+    class DoFnWithLongGaps(DoFn):
+      def process(self, element):
+        now = time.time()

Review Comment:
   Consider rewriting for readabilty
   ```
     emitted_at, unused_count = element
     processed_at = time.time()
     if processed_at - emitted_at > 25:
       yield ('Elements emitted took too long to process.', emitted_at, 
processed_at)
   ```



##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')
+
+  @pytest.mark.it_postcommit
+  @pytest.mark.sickbay_direct
+  @pytest.mark.sickbay_spark
+  @pytest.mark.sickbay_flink
+  @pytest.mark.timeout(
+      900)  # Timeout after 15 minutes to give Dataflow some extra time
+  def test_periodicsequence_outputs_valid_watermarks_it(self):
+    """Tests periodic sequence with watermarks on dataflow.
+    For testing that watermarks are being correctly emitted,
+    we make sure that there's not a long gap between an element being
+    emitted and being correctly aggregated.
+    """
+    class DoFnWithLongGaps(DoFn):
+      def process(self, element):
+        now = time.time()
+        if now - element[0] > 25:
+          yield (element[0], now)
+
+    start_time = time.time()
+    # Run long enough for Dataflow to start up
+    duration = 540
+    end_time = start_time + duration
+    interval = 1
+
+    res = (
+        self.test_pipeline
+        | 'ImpulseElement' >> beam.Create([(start_time, end_time, interval)])
+        | 'ImpulseSeqGen' >> PeriodicSequence()
+        | 'MapToCurrentTime' >> beam.Map(lambda element: time.time())
+        | 'window_into' >> beam.WindowInto(
+            window.FixedWindows(2),
+            accumulation_mode=trigger.AccumulationMode.DISCARDING)
+        | beam.combiners.Count.PerElement()
+        | beam.ParDo(DoFnWithLongGaps()))
+    assert_that(res, is_empty())

Review Comment:
   we could also add an assertion that all windows don't fire at the same time, 
for example that there are at lease X different processing timestamps. This 
might be flakiness-prone though if pipeline takes too long to start and all 
windows fire at the beginning of the pipeline.



##########
sdks/python/apache_beam/transforms/periodicsequence_it_test.py:
##########
@@ -0,0 +1,92 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""Integration tests for cross-language transform expansion."""
+
+# pytype: skip-file
+
+import time
+import unittest
+
+import pytest
+
+import apache_beam as beam
+from apache_beam import Pipeline
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import is_empty
+from apache_beam.transforms import trigger
+from apache_beam.transforms import window
+from apache_beam.transforms.core import DoFn
+from apache_beam.transforms.periodicsequence import PeriodicSequence
+
+
[email protected](
+    not TestPipeline().get_pipeline_options().view_as(
+        StandardOptions).streaming,
+    "Watermark tests are only valid for streaming jobs.")
+class PeriodicSequenceIT(unittest.TestCase):
+  def setUp(self):
+    self.test_pipeline = TestPipeline(is_integration_test=True)
+    self.runner_name = type(self.test_pipeline.runner).__name__
+    self.project = self.test_pipeline.get_option('project')
+
+  @pytest.mark.it_postcommit
+  @pytest.mark.sickbay_direct
+  @pytest.mark.sickbay_spark
+  @pytest.mark.sickbay_flink
+  @pytest.mark.timeout(
+      900)  # Timeout after 15 minutes to give Dataflow some extra time
+  def test_periodicsequence_outputs_valid_watermarks_it(self):
+    """Tests periodic sequence with watermarks on dataflow.
+    For testing that watermarks are being correctly emitted,
+    we make sure that there's not a long gap between an element being
+    emitted and being correctly aggregated.
+    """
+    class DoFnWithLongGaps(DoFn):
+      def process(self, element):
+        now = time.time()
+        if now - element[0] > 25:
+          yield (element[0], now)
+
+    start_time = time.time()
+    # Run long enough for Dataflow to start up
+    duration = 540
+    end_time = start_time + duration
+    interval = 1
+
+    res = (
+        self.test_pipeline
+        | 'ImpulseElement' >> beam.Create([(start_time, end_time, interval)])
+        | 'ImpulseSeqGen' >> PeriodicSequence()
+        | 'MapToCurrentTime' >> beam.Map(lambda element: time.time())
+        | 'window_into' >> beam.WindowInto(
+            window.FixedWindows(2),
+            accumulation_mode=trigger.AccumulationMode.DISCARDING)
+        | beam.combiners.Count.PerElement()
+        | beam.ParDo(DoFnWithLongGaps()))
+    assert_that(res, is_empty())
+
+    proto_pipeline, _ = self.test_pipeline.to_runner_api(return_context=True)

Review Comment:
   What was the purpose of the RunnerAPI roundtrip here instead of calling 
`self.test_pipeline.run().wait_until_finish()` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to