XCTests - Transparency, Consent and Control Causes Hang

I have a suite of tests for a macOS target that perform various file access operations (opening files to read/write contents, copying/moving/deleting files, iterating directories, etc.). Any operation that touches the Desktop, Documents or Downloads folder results in a one time ~15 second hang. This only happens once. No matter what order tests are run in, or what filesystem operation happens first, only the first such operation hangs like this, then the rest run nearly instantaneously.

This only happens on a macOS target. If I run the same tests in an iOS target, and perform the same file operations on the same files through the iOS simulator, this freeze doesn't happen. And it only happens in the three folders protected by Transparency, Consent and Control (Desktop, Downloads and Documents).

I first noticed this on C++ filesystem access operations (defined in std::filesystem), but I tested and confirmed it happens through Cocoa APIs too (like [NSData dataWithContentsOfFile].

I'm not sure why it would hang rather than just prompt for access (which I have a vague memory of it doing the first time I ran the test suite) or simply fail. But does anyone know of any settings that can be added to, say, Security & Privacy that will stop the hang from occurring? Without it the tests would run in probably a 100th of a second, so 15 seconds is a massive slowdown.

For up, I’m going to use the terminology defined in On File System Permissions.

Why is your test code touching MAC-protected directories? Are you trying to test how your app deals with MAC?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The code repo includes some sample files and directories that the tests use, and the repo happens to be cloned into a folder inside my Documents folder on my machine. That's why it's trying to access files there.

the repo happens to be cloned into a folder inside my Documents folder on my machine.

You have a couple of options here:

  • Continue trying to investigate this issue.

  • Move the repro to a directory not protected by MAC.

I know which one I’d do. It’s the expedient choice, but it may even be the right choice. MAC is a user-focused technology and it’s not uncommon for developers to have to take special steps to bypass user-level protections (consider the newly introduced Developer Mode on iOS).

I usually put my repos in a directory within my home directory and then, if I want easy access to one, I make an alias to it on my desktop.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

XCTests - Transparency, Consent and Control Causes Hang
 
 
Q