Skip to content

Commit 06ef1e9

Browse files
authored
source-postgres: enable SAT high test strictness level (#20549)
1 parent 6c1869b commit 06ef1e9

File tree

13 files changed

+151
-10
lines changed

13 files changed

+151
-10
lines changed

airbyte-integrations/bases/source-acceptance-test/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 0.2.25
4+
Enable bypass reason for future state test config.[#20549](https://github.com/airbytehq/airbyte/pull/20549)
5+
36
## 0.2.24
47
Check for nullity of docker runner in `previous_discovered_catalog_fixture`.[#20899](https://github.com/airbytehq/airbyte/pull/20899)
58

airbyte-integrations/bases/source-acceptance-test/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ COPY pytest.ini setup.py ./
3333
COPY source_acceptance_test ./source_acceptance_test
3434
RUN pip install .
3535

36-
LABEL io.airbyte.version=0.2.24
36+
LABEL io.airbyte.version=0.2.25
3737
LABEL io.airbyte.name=airbyte/source-acceptance-test
3838

3939
ENTRYPOINT ["python", "-m", "pytest", "-p", "source_acceptance_test.plugin", "-r", "fEsx"]

airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class FullRefreshConfig(BaseConfig):
144144
class FutureStateConfig(BaseConfig):
145145
future_state_path: Optional[str] = Field(description="Path to a state file with values in far future")
146146
missing_streams: List[EmptyStreamConfiguration] = Field(default=[], description="List of missings streams with valid bypass reasons.")
147+
bypass_reason: Optional[str]
147148

148149

149150
class IncrementalConfig(BaseConfig):

airbyte-integrations/bases/source-acceptance-test/source_acceptance_test/tests/test_incremental.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
@pytest.fixture(name="future_state_configuration")
1919
def future_state_configuration_fixture(inputs, base_path, test_strictness_level) -> Tuple[Path, List[EmptyStreamConfiguration]]:
2020
"""Fixture with connector's future state path (relative to base_path)"""
21-
if inputs.future_state and inputs.future_state.future_state_path:
21+
if inputs.future_state and inputs.future_state.bypass_reason is not None:
22+
pytest.skip("`future_state` has a bypass reason, skipping.")
23+
elif inputs.future_state and inputs.future_state.future_state_path:
2224
return Path(base_path) / inputs.future_state.future_state_path, inputs.future_state.missing_streams
2325
elif test_strictness_level is Config.TestStrictnessLevel.high:
24-
pytest.fail("High test strictness level error: a future state configuration must be provided in high test strictness level.")
26+
pytest.fail(
27+
"High test strictness level error: a future state configuration must be provided in high test strictness level or a bypass reason should be filled."
28+
)
2529
else:
2630
pytest.skip("`future_state` not specified, skipping.")
2731

airbyte-integrations/bases/source-acceptance-test/unit_tests/test_incremental.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,32 +695,39 @@ def test_state_with_abnormally_large_values(mocker, read_output, expectation):
695695
[
696696
pytest.param(
697697
Config.TestStrictnessLevel.high,
698-
MagicMock(future_state=MagicMock(future_state_path="my_future_state_path", missing_streams=["foo", "bar"])),
698+
MagicMock(future_state=MagicMock(future_state_path="my_future_state_path", missing_streams=["foo", "bar"], bypass_reason=None)),
699699
False,
700700
False,
701701
id="high test strictness level, future_state_path and missing streams are defined: run the test.",
702702
),
703703
pytest.param(
704704
Config.TestStrictnessLevel.low,
705-
MagicMock(future_state=MagicMock(future_state_path="my_future_state_path", missing_streams=["foo", "bar"])),
705+
MagicMock(future_state=MagicMock(future_state_path="my_future_state_path", missing_streams=["foo", "bar"], bypass_reason=None)),
706706
False,
707707
False,
708708
id="low test strictness level, future_state_path and missing_streams are defined: run the test.",
709709
),
710710
pytest.param(
711711
Config.TestStrictnessLevel.high,
712-
MagicMock(future_state=MagicMock(future_state_path=None)),
712+
MagicMock(future_state=MagicMock(future_state_path=None, bypass_reason=None)),
713713
True,
714714
False,
715715
id="high test strictness level, future_state_path and missing streams are defined: fail the test.",
716716
),
717717
pytest.param(
718718
Config.TestStrictnessLevel.low,
719-
MagicMock(future_state=MagicMock(future_state_path=None)),
719+
MagicMock(future_state=MagicMock(future_state_path=None, bypass_reason=None)),
720720
False,
721721
True,
722722
id="low test strictness level, future_state_path not defined: skip the test.",
723723
),
724+
pytest.param(
725+
Config.TestStrictnessLevel.high,
726+
MagicMock(future_state=MagicMock(bypass_reason="valid bypass reason")),
727+
False,
728+
True,
729+
id="high test strictness level, bypass_reason: skip test.",
730+
),
724731
],
725732
)
726733
def test_future_state_configuration_fixture(mocker, test_strictness_level, inputs, expect_fail, expect_skip):
Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
# See [Source Acceptance Tests](https://docs.airbyte.com/connector-development/testing-connectors/source-acceptance-tests-reference)
22
# for more information about how to configure these tests
33
connector_image: airbyte/source-postgres:dev
4-
tests:
4+
test_strictness_level: high
5+
acceptance_tests:
56
spec:
6-
- spec_path: "src/test-integration/resources/expected_spec.json"
7-
config_path: "src/test-integration/resources/dummy_config.json"
7+
tests:
8+
- spec_path: "src/test-integration/resources/expected_spec.json"
9+
config_path: "secrets/config.json"
10+
- spec_path: "src/test-integration/resources/expected_spec.json"
11+
config_path: "secrets/config_cdc.json"
12+
connection:
13+
tests:
14+
- config_path: "secrets/config.json"
15+
status: "succeed"
16+
- config_path: "secrets/config_cdc.json"
17+
status: "succeed"
18+
discovery:
19+
tests:
20+
- config_path: "secrets/config.json"
21+
- config_path: "secrets/config_cdc.json"
22+
basic_read:
23+
tests:
24+
- config_path: "secrets/config.json"
25+
expect_records:
26+
path: "integration_tests/expected_records.txt"
27+
- config_path: "secrets/config_cdc.json"
28+
expect_records:
29+
path: "integration_tests/expected_records.txt"
30+
full_refresh:
31+
tests:
32+
- config_path: "secrets/config.json"
33+
- config_path: "secrets/config_cdc.json"
34+
incremental:
35+
tests:
36+
- config_path: "secrets/config.json"
37+
configured_catalog_path: "integration_tests/incremental_configured_catalog.json"
38+
future_state:
39+
bypass_reason: "A java.lang.NullPointerException is thrown when a state with an invalid cursor value is passed"
40+
- config_path: "secrets/config_cdc.json"
41+
configured_catalog_path: "integration_tests/incremental_configured_catalog.json"
42+
future_state:
43+
bypass_reason: "A java.lang.NullPointerException is thrown when a state with an invalid cursor value is passed"

airbyte-integrations/connectors/source-postgres/acceptance-test-docker.sh

100644100755
File mode changed.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This directory contains files used to run Source Acceptance Tests.
2+
* `abnormal_state.json` describes a connector state with a non-existing cursor value.
3+
* `expected_records.txt` lists all the records expected as the output of the basic read operation.
4+
* `incremental_configured_catalog.json` is a configured catalog used as an input of the `incremental` test.
5+
* `seed.sql` is the query we manually ran on a test postgres instance to seed it with test data and enable CDC.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"type": "STREAM",
4+
"stream": {
5+
"stream_state": {
6+
"id": 4
7+
},
8+
"stream_descriptor": {
9+
"name": "id_and_name"
10+
}
11+
}
12+
}
13+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{"stream": "id_and_name", "data": {"id": 1, "name": "picard"}, "emitted_at": 999999}
2+
{"stream": "id_and_name", "data": {"id": 2, "name": "crusher"}, "emitted_at": 999999}
3+
{"stream": "id_and_name", "data": {"id": 3, "name": "vash"}, "emitted_at": 999999}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"streams": [
3+
{
4+
"stream": {
5+
"name": "id_and_name",
6+
"json_schema": {
7+
"type": "object",
8+
"properties": {
9+
"name": {
10+
"type": "string"
11+
},
12+
"id": {
13+
"type": "number",
14+
"airbyte_type": "integer"
15+
}
16+
}
17+
},
18+
"supported_sync_modes": [
19+
"full_refresh",
20+
"incremental"
21+
],
22+
"default_cursor_field": [],
23+
"source_defined_primary_key": [],
24+
"namespace": "public"
25+
},
26+
"sync_mode": "incremental",
27+
"destination_sync_mode": "append",
28+
"cursor_field": ["id"],
29+
"user_defined_primary_key": ["id"]
30+
}
31+
]
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
ALTER ROLE postgres WITH REPLICATION;
2+
3+
CREATE
4+
TABLE
5+
id_and_name(
6+
id INTEGER,
7+
name VARCHAR(200)
8+
);
9+
10+
INSERT
11+
INTO
12+
id_and_name(
13+
id,
14+
name
15+
)
16+
VALUES(
17+
1,
18+
'picard'
19+
),
20+
(
21+
2,
22+
'crusher'
23+
),
24+
(
25+
3,
26+
'vash'
27+
);
28+
29+
SELECT
30+
pg_create_logical_replication_slot(
31+
'debezium_slot',
32+
'pgoutput'
33+
);
34+
35+
CREATE
36+
PUBLICATION publication FOR ALL TABLES;

docs/connector-development/testing-connectors/source-acceptance-tests-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ This test verifies that sync produces no records when run with the STATE with ab
236236
| `configured_catalog_path` | string | `integration_tests/configured_catalog.json` | Path to configured catalog | |
237237
| `future_state_path` | string | None | Path to the state file with abnormally large cursor values | |
238238
| `timeout_seconds` | int | 20\*60 | Test execution timeout in seconds | |
239+
| `bypass_reason` | string | None | Explain why this test is bypassed | |
239240

240241
## Strictness level
241242

0 commit comments

Comments
 (0)