Compare commits

...
Author SHA1 Message Date
Nikolay Edigaryev 4e0dbcea4b integration-tests: use HttpWaitStrategy 2026-05-13 14:09:24 +02:00
Sean McLoughlin 3f1624e31a fix(control-socket): use .path instead of .path() for stale socket cleanup
Use URL's .path property instead of .path() method when removing stale
control sockets in ControlSocket.run(). The .path() method returns only
the relative component ('control.sock') while .path resolves to the
full absolute path. Since the cwd change happens after the cleanup,
removeItem silently failed to find the socket.

Add unit tests verifying controlSocketURL resolves correctly for both
absolute cleanup and relative binding use cases.

Fixes: https://github.com/cirruslabs/tart/issues/1220
2026-05-12 23:54:42 +02:00
3 changed files with 31 additions and 7 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ class ControlSocket {
func run() async throws {
// Remove control socket file from previous "tart run" invocations,
// if any, otherwise we may get the "address already in use" error
try? FileManager.default.removeItem(atPath: controlSocketURL.path())
try? FileManager.default.removeItem(atPath: controlSocketURL.path)
// Change the current working directory to a VM's base directory
// to work around Unix domain socket 104 byte limitation [1]
@@ -0,0 +1,28 @@
import XCTest
@testable import tart
final class ControlSocketURLTests: XCTestCase {
func testControlSocketURLResolvesToAbsolutePath() throws {
let baseURL = URL(fileURLWithPath: "/Users/test/.tart/vms/myvm/")
let vmDir = VMDirectory(baseURL: baseURL)
// The .path property resolves relative URLs to absolute paths,
// which is required for stale socket cleanup in ControlSocket.run()
// since it happens before the working directory is changed.
XCTAssertEqual(
vmDir.controlSocketURL.path,
"/Users/test/.tart/vms/myvm/control.sock"
)
}
func testControlSocketURLRelativePathIsJustFilename() throws {
let baseURL = URL(fileURLWithPath: "/Users/test/.tart/vms/myvm/")
let vmDir = VMDirectory(baseURL: baseURL)
// The .relativePath is used for socket binding after cwd is changed
XCTAssertEqual(
vmDir.controlSocketURL.relativePath,
"control.sock"
)
}
}
+2 -6
View File
@@ -1,7 +1,5 @@
import requests
from testcontainers.core.waiting_utils import wait_container_is_ready
from testcontainers.core.container import DockerContainer
from testcontainers.core.wait_strategies import HttpWaitStrategy
class DockerRegistry(DockerContainer):
@@ -10,11 +8,9 @@ class DockerRegistry(DockerContainer):
def __init__(self):
super().__init__("registry:2")
self.with_exposed_ports(self._default_exposed_port)
self.waiting_for(HttpWaitStrategy(self._default_exposed_port, "/v2/").for_status_code(200))
@wait_container_is_ready(requests.exceptions.ConnectionError)
def remote_name(self, for_vm: str):
exposed_port = self.get_exposed_port(self._default_exposed_port)
requests.get(f"http://127.0.0.1:{exposed_port}/v2/")
return f"127.0.0.1:{exposed_port}/tart/{for_vm}:latest"