Skip to content

Commit bf0d46c

Browse files
authored
Mitigate breaking build using SaveDebugRecordingsOnFailure (Azure#16599)
Tested with debug and release builds with and without SYSTEM_TEAMPROJECTID defined (used in a few projects for detecting AzDO). Doing this in the setter works when set in either a fixture's constructor or in a test method, while doing so in SetUp is too early, and in TearDown doesn't propagate.
1 parent 67318b0 commit bf0d46c

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,27 @@ public abstract class RecordedTestBase : ClientTestBase
3434
(char)31, ':', '*', '?', '\\', '/'
3535
});
3636

37-
#if DEBUG
3837
/// <summary>
3938
/// Flag you can (temporarily) enable to save failed test recordings
4039
/// and debug/re-run at the point of failure without re-running
4140
/// potentially lengthy live tests. This should never be checked in
42-
/// and will be compiled out of release builds to help make that easier
41+
/// and will throw an exception from CI builds to help make that easier
4342
/// to spot.
4443
/// </summary>
45-
public bool SaveDebugRecordingsOnFailure { get; set; } = false;
46-
#endif
44+
public bool SaveDebugRecordingsOnFailure
45+
{
46+
get => _saveDebugRecordingsOnFailure;
47+
set
48+
{
49+
if (value && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SYSTEM_TEAMPROJECTID")))
50+
{
51+
throw new AssertionException($"Setting {nameof(SaveDebugRecordingsOnFailure)} must not be merged");
52+
}
53+
54+
_saveDebugRecordingsOnFailure = value;
55+
}
56+
}
57+
private bool _saveDebugRecordingsOnFailure;
4758

4859
protected RecordedTestBase(bool isAsync) : this(isAsync, RecordedTestUtilities.GetModeFromEnvironment())
4960
{

sdk/synapse/Azure.Analytics.Synapse.AccessControl/tests/AccessControlClientTestBase.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public abstract class AccessControlClientTestBase : RecordedTestBase<SynapseTest
1616

1717
protected AccessControlClientTestBase(bool isAsync) : base(isAsync)
1818
{
19-
#if DEBUG
20-
SaveDebugRecordingsOnFailure = true;
21-
#endif
2219
}
2320

2421
public override void StartTestRecording()

sdk/synapse/Azure.Analytics.Synapse.Artifacts/tests/ArtifactsClientTestBase.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public abstract class ArtifactsClientTestBase : RecordedTestBase<SynapseTestEnvi
2626

2727
protected ArtifactsClientTestBase(bool isAsync) : base(isAsync)
2828
{
29-
#if DEBUG
30-
SaveDebugRecordingsOnFailure = true;
31-
#endif
3229
}
3330

3431
public override void StartTestRecording()

sdk/synapse/Azure.Analytics.Synapse.ManagedPrivateEndpoints/tests/ManagedPrivateEndpointsClientTestBase.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public abstract class ManagedPrivateEndpointsClientTestBase : RecordedTestBase<S
1616

1717
protected ManagedPrivateEndpointsClientTestBase(bool isAsync) : base(isAsync)
1818
{
19-
#if DEBUG
20-
SaveDebugRecordingsOnFailure = true;
21-
#endif
2219
}
2320

2421
public override void StartTestRecording()

sdk/synapse/Azure.Analytics.Synapse.Monitoring/tests/MonitoringClientTestBase.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public abstract class MonitoringClientTestBase : RecordedTestBase<SynapseTestEnv
1616

1717
protected MonitoringClientTestBase(bool isAsync) : base(isAsync)
1818
{
19-
#if DEBUG
20-
SaveDebugRecordingsOnFailure = true;
21-
#endif
2219
}
2320

2421
public override void StartTestRecording()

sdk/synapse/Azure.Analytics.Synapse.Spark/tests/SparkClientTestBase.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public abstract class SparkClientTestBase : RecordedTestBase<SynapseTestEnvironm
1919

2020
protected SparkClientTestBase(bool isAsync) : base(isAsync)
2121
{
22-
#if DEBUG
23-
SaveDebugRecordingsOnFailure = true;
24-
#endif
2522
}
2623

2724
public override void StartTestRecording()

0 commit comments

Comments
 (0)