apple / apple/swift-distributed-actors

Consider Receptable in TestKit

Open
#282 0 comments 0 reactions 0 assignees View on GitHub
1 - triaged help wanted t:actor t:testkit
Dominant language
Swift
Stars
679
Forks
84
PR merge metrics
No merged PRs in 30d

Description

It is UNSAFE to do stuff like:

```swift
// pseudo code

func mytest() {
var myMutableThing = ..

system.spawn(.receive { _ in
myMutableThing.mutate() // UNSAFE DONT DO THIS
}).tell("hi")
}

testkit.eventually {
}
```

For simple types it may actually happen to accidentally sometimes work, but in general this is concurrent access to mutable data and is therefore unsafe in general.

We could offer:

```swift
let receptacle = testKit.receptacle(of: Thing.self)

system.spawn(.receive { _ in
receptacle.set("foo")
}).tell("hi")

await receptacle.expect("foo", within: .seconds(2))
```

it would mean people don't have to get out NIO just to test some actor thing

Contributor guide

Open the contributing guide

Research direction

Start by locating TestKit and its existing eventually API, then review how actor callbacks interact with shared mutable test state. Done means TestKit offers a receptacle-based way to record and await values without requiring NIO, with coverage for the proposed usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.