Skip to content

Commit bb4002f

Browse files
rolfbjarneCopilot
andcommitted
[tests] Avoid writing to the Documents directory in UrlTest and AudioConverterTest.
CI run 15215315 (PR #24249) showed the exact same class of hang as the previous fix (ccc70fb), just one test further down the alphabetical list: after the Documents-directory write in FileManagerTest.GetSkipBackupAttribute was fixed, macOS/Mac Catalyst runs progressed further into Foundation.UrlTest, then hung again with the same getxattr-on-main-thread signature right after UrlTest.Invalid_29510 - i.e. at UrlTest.IsExcludedFromBackupKey, the next test alphabetically. IsExcludedFromBackupKey also writes a scratch file into the user's Documents directory (NSSearchPathDirectory.DocumentDirectory) before manipulating NSUrl.IsExcludedFromBackupKey on it. Now that tests run through the new spawner tool (which disclaims process responsibility, so the ephemeral test app is checked on its own TCC status instead of inheriting an already-approved ancestor's), this write triggers a fresh 'Files and Folders' authorization prompt that hangs forever with no interactive session to answer it. Fix it the same way as the previous commit: use NSFileManager.TemporaryDirectory instead, which isn't behind a TCC prompt and is already the established convention for scratch files elsewhere in this test suite. While auditing the rest of the test suite for the same anti-pattern (a search for NSSearchPathDirectory.DocumentDirectory across tests/monotouch-test), also fix AudioConverterTest.ConvertWithPacketDependencies, which wrote its output audio file into the Documents directory instead of using the DoWithTemporaryDirectory helper that its sibling tests in the same file (Convert, CreateWithOptions) already use for exactly this reason. This wasn't yet confirmed as an observed CI hang (it likely wasn't reached before the UrlTest hang), but it has the identical risk and would very likely have been the next hang once UrlTest was fixed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ca98fc3c-135b-4bad-80dc-50262be55c90
1 parent ccc70fb commit bb4002f

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

tests/monotouch-test/AudioToolbox/AudioConverterTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,11 @@ public void ConvertWithPacketDependencies (AudioFormatType targetType)
167167
TestRuntime.AssertXcodeVersion (26, 0);
168168

169169
var sourcePath = Path.Combine (NSBundle.MainBundle.ResourcePath, "Hand.wav");
170-
var paths = NSSearchPath.GetDirectories (NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
171170

172-
var output1 = Path.Combine (paths [0], "output1.caf");
173-
Convert (sourcePath, output1, targetType, withPacketDependencies: true);
171+
DoWithTemporaryDirectory ((temporaryDirectory) => {
172+
var output1 = Path.Combine (temporaryDirectory, "output1.caf");
173+
Convert (sourcePath, output1, targetType, withPacketDependencies: true);
174+
});
174175
}
175176

176177
void Convert (string sourceFilePath, string destinationFilePath, AudioFormatType outputFormatType, int? sampleRate = null, AudioConverterOptions? options = null, bool withPacketDependencies = false)

tests/monotouch-test/Foundation/UrlTest.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public void IsExcludedFromBackupKey ()
4545
Assert.That (value, Is.TypeOf (typeof (NSNumber)), "NSNumber");
4646
Assert.That ((int) (value as NSNumber), Is.EqualTo (0), "0");
4747

48-
var paths = NSSearchPath.GetDirectories (NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
49-
var filename = Path.Combine (paths [0], $"DoNotBackupMe-NSUrl-{Process.GetCurrentProcess ().Id}");
48+
// Use the temporary directory instead of the Documents directory: writing to the Documents
49+
// directory can trigger a TCC ("Files and Folders") permission prompt on macOS, which hangs
50+
// forever in CI (there's no user around to answer the prompt).
51+
var filename = Path.Combine (NSFileManager.TemporaryDirectory, $"DoNotBackupMe-NSUrl-{Process.GetCurrentProcess ().Id}");
5052
try {
5153
File.WriteAllText (filename, "not worth a bit");
5254
using (NSUrl url = NSUrl.FromFilename (filename)) {

0 commit comments

Comments
 (0)