Communication between instances
For some test plans, it is useful to pass information from one instance to another. In addition to direct network connectivity, test plans can pass information between instances using the Testground sync service.
In this tutorial, we will explore typed message passing through the Testground sync service.
Lets create a plan in which one of the plans produces a struct which is re-constructed on the distant end. First, I'll show short snippets with the relevant information, and the whole test plan will be shown at the end.
Setting up thetopic
topicTransferrable is the value type we will be transferring.
type Transferrable struct {
Name string
FavoriteSport int
CareWhoKnows bool
}The value will be transferred over a topic. Think of the topic as a named and typed channel for transferring values between plan instances. This topic is named transfer-key and the value type I expect to get out of it is pointer to Transferrable.
st := sync.NewTopic("transfer-key", &Transferrable{})Publishing to a topic
topicTo write to a topic, create a bounded client and use it to publish to the topic we have just defined.
ctx := context.Background()
client := sync.MustBoundClient(ctx, runenv)
defer client.Close()
client.Publish(ctx, st, &Transferrable{"Guy#1", 1, false})Reading from a topic
topicSubscribe to the topic we created earlier and set up a channel to receive the values.
Who subscribes and who publishes?
This question is left up to the plan writer, and certainly different situations will call for different implementations. In this example, all the plans will publish and all will subscribe, but there are scenarios where this is inappropriate.
Full Example
Run with multiple instances:
?> Notice that instances is set to 4. Four instances will run at the same time.
Last updated