Skip to content

Commit

Permalink
Merge pull request #2462 from fishtown-analytics/fix/version-2-test-i…
Browse files Browse the repository at this point in the history
…ntermittent-failures

Fix config-version 2 test intermittent failures
  • Loading branch information
beckjake committed May 15, 2020
2 parents 1d543b3 + 5c76cfb commit 5734fb8
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: 'test'
version: '1.0'
config-version: 2

profile: 'default'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: early_hooks
version: '1.0'
config-version: 2
on-run-start:
- create table {{ var('test_create_table') }} as (select 1 as id)
- create table {{ var('test_create_second_table') }} as (select 3 as id)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: late_hooks
version: '1.0'
config-version: 2
on-run-start:
- insert into {{ var('test_create_table') }} values (2)
- insert into {{ var('test_create_second_table') }} values (4)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

name: 'local_dep'
version: '1.0'
config-version: 2

profile: 'default'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile
from test.integration.base import DBTIntegrationTest, use_profile
from dbt.exceptions import CompilationException
from dbt import deprecations


class TestSimpleDependency(DBTIntegrationTest):
Expand All @@ -25,17 +26,11 @@ def packages_config(self):
"packages": [
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'warn-unpinned': False,
'revision': 'dbt/0.17.0',
}
]
}

def run_dbt(self, cmd=None, *args, **kwargs):
if cmd and cmd[0] != 'deps':
strict = kwargs.pop('strict', False)
kwargs['strict'] = strict
return super().run_dbt(cmd, *args, **kwargs)

def run_deps(self):
return self.run_dbt(["deps"])

Expand All @@ -45,30 +40,30 @@ def test_postgres_simple_dependency(self):
results = self.run_dbt(["run"])
self.assertEqual(len(results), 4)

self.assertTablesEqual("seed","table_model")
self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed","incremental")
self.assertTablesEqual("seed", "table_model")
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")

self.assertTablesEqual("seed_summary","view_summary")
self.assertTablesEqual("seed_summary", "view_summary")

self.run_sql_file("update.sql")

self.run_deps()
results = self.run_dbt(["run"])
self.assertEqual(len(results), 4)

self.assertTablesEqual("seed","table_model")
self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed","incremental")
self.assertTablesEqual("seed", "table_model")
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")

@use_profile('postgres')
def test_postgres_simple_dependency_with_models(self):
self.run_deps()
results = self.run_dbt(["run", '--models', 'view_model+'])
self.assertEqual(len(results), 2)

self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed_summary","view_summary")
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed_summary", "view_summary")

created_models = self.get_models_in_schema()

Expand Down Expand Up @@ -105,9 +100,14 @@ def packages_config(self):

@use_profile('postgres')
def test_postgres_simple_dependency(self):
self.run_dbt(['deps'], strict=False)
with self.assertRaises(CompilationException):
# hack: insert the config version warning into the active deprecations,
# to avoid triggering on that, since the unpinned branch also should
# warn about the version.
deprecations.active_deprecations.add('dbt-project-yaml-v1')
with self.assertRaises(CompilationException) as exc:
self.run_dbt(["deps"])
assert 'is not pinned' in str(exc.exception)
self.run_dbt(['deps'], strict=False)


class TestSimpleDependencyWithDuplicates(DBTIntegrationTest):
Expand All @@ -126,11 +126,11 @@ def packages_config(self):
"packages": [
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'warn-unpinned': False,
'revision': 'dbt/0.17.0',
},
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project.git',
'warn-unpinned': False,
'revision': 'dbt/0.17.0',
}
]
}
Expand Down Expand Up @@ -192,20 +192,19 @@ def packages_config(self):
"packages": [
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'master',
'warn-unpinned': False,
'revision': 'dbt/0.17.0',
},
]
}

def deps_run_assert_equality(self):
self.run_dbt(["deps"])
results = self.run_dbt(["run"], strict=False)
results = self.run_dbt(["run"])
self.assertEqual(len(results), 4)

self.assertTablesEqual("seed","table_model")
self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed","incremental")
self.assertTablesEqual("seed", "table_model")
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")

created_models = self.get_models_in_schema()

Expand All @@ -218,7 +217,7 @@ def deps_run_assert_equality(self):
def test_postgres_simple_dependency(self):
self.deps_run_assert_equality()

self.assertTablesEqual("seed_summary","view_summary")
self.assertTablesEqual("seed_summary", "view_summary")

self.run_sql_file("update.sql")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ def schema(self):
def models(self):
return "models"

def run_dbt(self, *args, **kwargs):
strict = kwargs.pop('strict', False)
kwargs['strict'] = strict
return super().run_dbt(*args, **kwargs)

class TestSimpleDependencyWithConfigs(BaseTestSimpleDependencyWithConfigs):
@property
Expand All @@ -27,7 +23,7 @@ def packages_config(self):
"packages": [
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'with-configs',
'revision': 'with-configs-0.17.0',
},
]
}
Expand All @@ -49,10 +45,10 @@ def test_postgres_simple_dependency(self):
results = self.run_dbt(["run"])
self.assertEqual(len(results), 5)

self.assertTablesEqual('seed_config_expected_1',"config")
self.assertTablesEqual("seed","table_model")
self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed","incremental")
self.assertTablesEqual('seed_config_expected_1', "config")
self.assertTablesEqual("seed", "table_model")
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")


class TestSimpleDependencyWithOverriddenConfigs(BaseTestSimpleDependencyWithConfigs):
Expand All @@ -63,7 +59,7 @@ def packages_config(self):
"packages": [
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'with-configs',
'revision': 'with-configs-0.17.0',
},
]
}
Expand All @@ -88,10 +84,10 @@ def test_postgres_simple_dependency(self):
results = self.run_dbt(["run"])
self.assertEqual(len(results), 5)

self.assertTablesEqual('seed_config_expected_2',"config")
self.assertTablesEqual("seed","table_model")
self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed","incremental")
self.assertTablesEqual('seed_config_expected_2', "config")
self.assertTablesEqual("seed", "table_model")
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")


class TestSimpleDependencyWithModelSpecificOverriddenConfigs(BaseTestSimpleDependencyWithConfigs):
Expand All @@ -102,7 +98,7 @@ def packages_config(self):
"packages": [
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'with-configs',
'revision': 'with-configs-0.17.0',
},
]
}
Expand Down Expand Up @@ -132,13 +128,13 @@ def test_postgres_simple_dependency(self):
self.use_default_project()

self.run_dbt(["deps"])
results = self.run_dbt(["run"])
results = self.run_dbt(["run"], strict=False) # config is v1, can't use strict here
self.assertEqual(len(results), 5)

self.assertTablesEqual('seed_config_expected_3',"config")
self.assertTablesEqual("seed","table_model")
self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed","incremental")
self.assertTablesEqual('seed_config_expected_3', "config")
self.assertTablesEqual("seed", "table_model")
self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")


class TestSimpleDependencyWithModelSpecificOverriddenConfigsAndMaterializations(BaseTestSimpleDependencyWithConfigs):
Expand All @@ -149,7 +145,7 @@ def packages_config(self):
"packages": [
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'with-configs',
'revision': 'with-configs-0.17.0',
},
]
}
Expand Down Expand Up @@ -186,12 +182,11 @@ def project_config(self):
@use_profile('postgres')
def test_postgres_simple_dependency(self):
self.run_dbt(["deps"])
results = self.run_dbt(["run"])
results = self.run_dbt(["run"], strict=False) # config is v1, can't use strict here
self.assertEqual(len(results), 3)

self.assertTablesEqual("seed","view_model")
self.assertTablesEqual("seed","incremental")

self.assertTablesEqual("seed", "view_model")
self.assertTablesEqual("seed", "incremental")

created_models = self.get_models_in_schema()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def models(self):
def packages_config(self):
return {
"packages": [
{'git': 'https://github.com/fishtown-analytics/dbt-integration-project', 'warn-unpinned': False}
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'dbt/0.17.0',
}
]
}

Expand Down
12 changes: 8 additions & 4 deletions test/integration/008_schema_tests_test/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def models(self):
@property
def project_config(self):
return {
'config-version': 2,
"macro-paths": ["macros-v2/malformed"],
}

Expand All @@ -150,8 +151,8 @@ def run_schema_validations(self):

@use_profile('postgres')
def test_postgres_malformed_macro_reports_error(self):
self.run_dbt(["deps"])
self.run_dbt()
self.run_dbt(['deps'])
self.run_dbt(strict=True)
expected_failure = 'not_null'

test_results = self.run_schema_validations()
Expand Down Expand Up @@ -182,6 +183,7 @@ def models(self):
@property
def project_config(self):
return {
'config-version': 2,
"on-run-start": ["{{ exceptions.raise_compiler_error('hooks called in tests -- error') if execute }}"],
"on-run-end": ["{{ exceptions.raise_compiler_error('hooks called in tests -- error') if execute }}"],
}
Expand Down Expand Up @@ -221,7 +223,7 @@ def packages_config(self):
},
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'warn-unpinned': False,
'revision': 'dbt/0.17.0',
},
]
}
Expand All @@ -232,6 +234,7 @@ def project_config(self):
# dbt-integration-project contains a schema.yml file
# both should work!
return {
'config-version': 2,
"macro-paths": ["macros-v2/macros"],
}

Expand All @@ -248,7 +251,7 @@ def run_schema_validations(self):
@use_profile('postgres')
def test_postgres_schema_tests(self):
self.run_dbt(["deps"])
results = self.run_dbt()
results = self.run_dbt(strict=False) # dbt-utils 0.13-support is config version 1
self.assertEqual(len(results), 4)

test_results = self.run_schema_validations()
Expand Down Expand Up @@ -351,6 +354,7 @@ def models(self):
@property
def project_config(self):
return {
'config-version': 2,
"macro-paths": ["macros-v2/macros"],
}

Expand Down
3 changes: 1 addition & 2 deletions test/integration/012_deprecation_tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def models(self):

@property
def project_config(self):
# No config-version set!
return {}
return {'config-version': 1}

@use_profile('postgres')
def test_postgres_project_deprecations_fail(self):
Expand Down
1 change: 1 addition & 0 deletions test/integration/014_hook_tests/test_model_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class TestPrePostModelHooksInConfig(BaseTestPrePost):
@property
def project_config(self):
return {
'config-version': 2,
'macro-paths': ['macros'],
}

Expand Down
10 changes: 8 additions & 2 deletions test/integration/016_macro_tests/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ def models(self):
def packages_config(self):
return {
'packages': [
{'git': 'https://github.com/fishtown-analytics/dbt-integration-project', 'warn-unpinned': False}
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'dbt/0.17.0',
},
]
}

Expand Down Expand Up @@ -94,7 +97,10 @@ def models(self):
def packages_config(self):
return {
'packages': [
{'git': 'https://github.com/fishtown-analytics/dbt-integration-project', 'warn-unpinned': False}
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'dbt/0.17.0',
}
]
}

Expand Down
5 changes: 4 additions & 1 deletion test/integration/023_exit_codes_test/test_exit_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ def models(self):
def packages_config(self):
return {
"packages": [
{'git': 'https://github.com/fishtown-analytics/dbt-integration-project', 'warn-unpinned': False}
{
'git': 'https://github.com/fishtown-analytics/dbt-integration-project',
'revision': 'dbt/0.17.0',
}
]
}

Expand Down
Loading

0 comments on commit 5734fb8

Please sign in to comment.