Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Wigley committed Nov 18, 2020
1 parent d57331f commit 7da7024
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 20 deletions.
6 changes: 3 additions & 3 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ def __init__(
is_partial_parse_enabled=self._partial_parse_enabled()
)

def track_loading_time(self):
def track_project_load(self):
invocation_id = dbt.tracking.active_user.invocation_id
dbt.tracking.track_loading_time({
dbt.tracking.track_project_load({
"invocation_id": invocation_id,
"project_id": self.root_project.hashed_name(),
"path_count": self._perf_info.path_count,
Expand Down Expand Up @@ -445,7 +445,7 @@ def load_all(
time.perf_counter() - start_load_all
)

loader.track_loading_time()
loader.track_project_load()

return manifest

Expand Down
4 changes: 2 additions & 2 deletions core/dbt/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ def track_invocation_start(config=None, args=None):
)


def track_loading_time(options):
def track_project_load(options):
context = [SelfDescribingJson(LOAD_ALL_TIMING_SPEC, options)]
assert active_user is not None, \
'Cannot track project loading time when active user is None'

track(
active_user,
category='dbt',
action='load_all_timing',
action='load_project',
label=active_user.invocation_id,
context=context
)
Expand Down
105 changes: 90 additions & 15 deletions test/integration/033_event_tracking_test/test_events.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from multiprocessing import context
from test.integration.base import DBTIntegrationTest, use_profile
import hashlib
import os
Expand Down Expand Up @@ -87,6 +88,24 @@ def run_event_test(
populated_contexts
)

def load_context(self):

def populate(project_id, user_id, invocation_id, version):
return [{
'schema': 'iglu:com.dbt/load_all_timing/jsonschema/1-0-0',
'data': {
'invocation_id': invocation_id,
'project_id': project_id,
'path_count': ANY,
'is_partial_parse_enabled': ANY,
'load_all_elapsed': ANY,
'parse_project_elapsed': ANY,
'patch_sources_elapsed': ANY,
'process_manifest_elapsed': ANY,
},
}]
return populate

def build_context(
self,
command,
Expand Down Expand Up @@ -174,7 +193,7 @@ def populate(project_id, user_id, invocation_id, version):


class TestEventTrackingSuccess(TestEventTracking):
@property
@ property
def packages_config(self):
return {
'packages': [
Expand All @@ -185,7 +204,7 @@ def packages_config(self):
],
}

@property
@ property
def project_config(self):
return {
'config-version': 2,
Expand All @@ -196,7 +215,7 @@ def project_config(self):
}
}

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_compile(self):
expected_calls = [
call(
Expand All @@ -205,6 +224,12 @@ def test__postgres_event_tracking_compile(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='invocation',
Expand All @@ -215,6 +240,7 @@ def test__postgres_event_tracking_compile(self):

expected_contexts = [
self.build_context('compile', 'start'),
self.load_context(),
self.build_context('compile', 'end', result_type='ok')
]

Expand All @@ -224,7 +250,7 @@ def test__postgres_event_tracking_compile(self):
expected_contexts
)

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_deps(self):
package_context = [
{
Expand Down Expand Up @@ -280,7 +306,7 @@ def test__postgres_event_tracking_deps(self):

self.run_event_test(["deps"], expected_calls, expected_contexts)

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_seed(self):
def seed_context(project_id, user_id, invocation_id, version):
return [{
Expand Down Expand Up @@ -312,6 +338,12 @@ def seed_context(project_id, user_id, invocation_id, version):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand All @@ -328,13 +360,14 @@ def seed_context(project_id, user_id, invocation_id, version):

expected_contexts = [
self.build_context('seed', 'start'),
self.load_context(),
seed_context,
self.build_context('seed', 'end', result_type='ok')
]

self.run_event_test(["seed"], expected_calls, expected_contexts)

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_models(self):
expected_calls = [
call(
Expand All @@ -343,6 +376,12 @@ def test__postgres_event_tracking_models(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand Down Expand Up @@ -371,6 +410,7 @@ def test__postgres_event_tracking_models(self):

expected_contexts = [
self.build_context('run', 'start'),
self.load_context(),
self.run_context(
hashed_contents='1e5789d34cddfbd5da47d7713aa9191c',
model_id='4fbacae0e1b69924b22964b457148fb8',
Expand All @@ -396,7 +436,7 @@ def test__postgres_event_tracking_models(self):
expected_contexts
)

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_model_error(self):
# cmd = ["run", "--model", "model_error"]
# self.run_event_test(cmd, event_run_model_error, expect_pass=False)
Expand All @@ -408,6 +448,12 @@ def test__postgres_event_tracking_model_error(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand All @@ -424,6 +470,7 @@ def test__postgres_event_tracking_model_error(self):

expected_contexts = [
self.build_context('run', 'start'),
self.load_context(),
self.run_context(
hashed_contents='4419e809ce0995d99026299e54266037',
model_id='576c3d4489593f00fad42b97c278641e',
Expand All @@ -442,7 +489,7 @@ def test__postgres_event_tracking_model_error(self):
expect_pass=False
)

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_tests(self):
# TODO: dbt does not track events for tests, but it should!
self.run_dbt(["run", "--model", "example", "example_2"])
Expand All @@ -454,6 +501,12 @@ def test__postgres_event_tracking_tests(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='invocation',
Expand All @@ -464,6 +517,7 @@ def test__postgres_event_tracking_tests(self):

expected_contexts = [
self.build_context('test', 'start'),
self.load_context(),
self.build_context('test', 'end', result_type='ok')
]

Expand All @@ -476,14 +530,14 @@ def test__postgres_event_tracking_tests(self):


class TestEventTrackingCompilationError(TestEventTracking):
@property
@ property
def project_config(self):
return {
'config-version': 2,
"source-paths": [self.dir("model-compilation-error")],
}

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_with_compilation_error(self):
expected_calls = [
call(
Expand Down Expand Up @@ -516,7 +570,7 @@ def test__postgres_event_tracking_with_compilation_error(self):

class TestEventTrackingUnableToConnect(TestEventTracking):

@property
@ property
def profile_config(self):
return {
'config': {
Expand Down Expand Up @@ -549,7 +603,7 @@ def profile_config(self):
}
}

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_unable_to_connect(self):
expected_calls = [
call(
Expand All @@ -558,6 +612,12 @@ def test__postgres_event_tracking_unable_to_connect(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='invocation',
Expand All @@ -568,6 +628,7 @@ def test__postgres_event_tracking_unable_to_connect(self):

expected_contexts = [
self.build_context('run', 'start'),
self.load_context(),
self.build_context('run', 'end', result_type='error')
]

Expand All @@ -580,14 +641,14 @@ def test__postgres_event_tracking_unable_to_connect(self):


class TestEventTrackingSnapshot(TestEventTracking):
@property
@ property
def project_config(self):
return {
'config-version': 2,
"snapshot-paths": ['snapshots']
}

@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_snapshot(self):
self.run_dbt(["run", "--models", "snapshottable"])

Expand All @@ -598,6 +659,12 @@ def test__postgres_event_tracking_snapshot(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY
),
call(
category='dbt',
action='run_model',
Expand All @@ -615,6 +682,7 @@ def test__postgres_event_tracking_snapshot(self):
# the model here has a raw_sql that contains the schema, which changes
expected_contexts = [
self.build_context('snapshot', 'start'),
self.load_context(),
self.run_context(
hashed_contents=ANY,
model_id='820793a4def8d8a38d109a9709374849',
Expand All @@ -634,7 +702,7 @@ def test__postgres_event_tracking_snapshot(self):


class TestEventTrackingCatalogGenerate(TestEventTracking):
@use_profile("postgres")
@ use_profile("postgres")
def test__postgres_event_tracking_catalog_generate(self):
# create a model for the catalog
self.run_dbt(["run", "--models", "example"])
Expand All @@ -646,6 +714,12 @@ def test__postgres_event_tracking_catalog_generate(self):
label='start',
context=ANY
),
call(
category='dbt',
action='load_project',
label=ANY,
context=ANY,
),
call(
category='dbt',
action='invocation',
Expand All @@ -656,6 +730,7 @@ def test__postgres_event_tracking_catalog_generate(self):

expected_contexts = [
self.build_context('generate', 'start'),
self.load_context(),
self.build_context('generate', 'end', result_type='ok')
]

Expand Down

0 comments on commit 7da7024

Please sign in to comment.