Skip to content

Commit

Permalink
Fix contention bug in windows (#7353)
Browse files Browse the repository at this point in the history
* Fix windows contention bug

* Cleanup in contention test

* formatting
  • Loading branch information
dpeng817 committed Apr 8, 2022
1 parent 4a0adb3 commit 60840ac
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dagster.core.definitions.reconstruct import get_ephemeral_repository_name
from dagster.core.telemetry import (
UPDATE_REPO_STATS,
cleanup_telemetry_logger,
get_or_create_dir_from_dagster_home,
hash_name,
log_workspace_stats,
Expand Down Expand Up @@ -68,6 +69,9 @@ def test_dagster_telemetry_enabled(caplog):
assert len(caplog.records) == 5
assert result.exit_code == 0

# Needed to avoid file contention issues on windows with the telemetry log file
cleanup_telemetry_logger()


def test_dagster_telemetry_disabled(caplog):
with instance_for_test(overrides={"telemetry": {"enabled": False}}):
Expand Down Expand Up @@ -117,6 +121,9 @@ def test_dagster_telemetry_unset(caplog):
assert len(caplog.records) == 5
assert result.exit_code == 0

# Needed to avoid file contention issues on windows with the telemetry log file
cleanup_telemetry_logger()


def test_repo_stats(caplog):
with tempfile.TemporaryDirectory() as temp_dir:
Expand Down Expand Up @@ -154,6 +161,9 @@ def test_repo_stats(caplog):
assert len(caplog.records) == 5
assert result.exit_code == 0

# Needed to avoid file contention issues on windows with the telemetry log file
cleanup_telemetry_logger()


def test_log_workspace_stats(caplog):
with instance_for_test(overrides={"telemetry": {"enabled": True}}) as instance:
Expand All @@ -169,6 +179,9 @@ def test_log_workspace_stats(caplog):

assert len(caplog.records) == 2

# Needed to avoid file contention issues on windows with the telemetry log file
cleanup_telemetry_logger()


# Sanity check that the hash function maps these similar names to sufficiently dissimilar strings
# From the docs, SequenceMatcher `does not yield minimal edit sequences, but does tend to yield
Expand All @@ -191,14 +204,20 @@ def test_write_telemetry_log_line_writes_to_dagster_home():
with tempfile.TemporaryDirectory() as temp_dir:
with environ({"DAGSTER_HOME": temp_dir}):
write_telemetry_log_line({"foo": "bar"})
with open(os.path.join(temp_dir, "logs/event.log"), "r") as f:
with open(os.path.join(temp_dir, "logs", "event.log"), "r") as f:
res = json.load(f)
assert res == {"foo": "bar"}

os.remove(os.path.join(temp_dir, "logs/event.log"))
# Needed to avoid file contention issues on windows with the telemetry log file
cleanup_telemetry_logger()

os.remove(os.path.join(temp_dir, "logs", "event.log"))
os.rmdir(os.path.join(temp_dir, "logs"))

write_telemetry_log_line({"foo": "bar"})
with open(os.path.join(temp_dir, "logs/event.log"), "r") as f:
with open(os.path.join(temp_dir, "logs", "event.log"), "r") as f:
res = json.load(f)
assert res == {"foo": "bar"}

# Needed to avoid file contention issues on windows with the telemetry log file
cleanup_telemetry_logger()

0 comments on commit 60840ac

Please sign in to comment.