github.com/anycable/anycable-go@v1.5.1/features/enats_clusters.testfile (about) 1 launch :rpc, "bundle exec anyt --only-rpc", 2 env: {"ANYCABLE_BROADCAST_ADAPTER" => "nats", "ANYCABLE_NATS_SERVERS" => "nats://localhost:4242"} 3 wait_tcp 50051 4 5 launch :anycable_1, 6 "./dist/anycable-go --broadcast_adapter=nats --embed_nats --enats_addr=nats://localhost:4242 --enats_cluster=nats://localhost:4342 --enats_gateway=nats://localhost:4442" 7 wait_tcp 8080 8 wait_tcp 4342 9 10 launch :anycable_2, 11 "./dist/anycable-go --port 8081 --broadcast_adapter=nats --embed_nats --enats_addr=nats://localhost:4243 --enats_cluster=nats://localhost:4343 --enats_cluster_routes=nats://localhost:4342" 12 wait_tcp 8081 13 14 launch :anycable_3, 15 "./dist/anycable-go --port 8082 --broadcast_adapter=nats --embed_nats --enats_addr=nats://localhost:4244 --enats_cluster=nats://localhost:4344 --enats_cluster_name=another-cluster --enats_gateway=nats://localhost:4444 --enats_gateways=anycable-cluster:nats://localhost:4442" 16 wait_tcp 8082 17 18 # We need to wait a bit for the NATS servers to find each other 19 sleep 2 20 21 scenario = [ 22 { 23 client: { 24 protocol: "action_cable", 25 name: "publisher", 26 actions: [ 27 { 28 subscribe: { 29 channel: "BenchmarkChannel" 30 } 31 }, 32 { 33 perform: { 34 channel: "BenchmarkChannel", 35 action: "broadcast", 36 data: { 37 message: "hello" 38 } 39 } 40 }, 41 { 42 receive: { 43 channel: "BenchmarkChannel", 44 data: { 45 message: "hello", 46 action: "broadcast" 47 } 48 } 49 }, 50 { 51 receive: { 52 channel: "BenchmarkChannel", 53 data: { 54 message: "hello", 55 action: "broadcastResult" 56 } 57 } 58 } 59 ] 60 } 61 }, 62 { 63 client: { 64 protocol: "action_cable", 65 name: "subscriber", 66 connection_options: { 67 url: "http://localhost:8081/cable" 68 }, 69 actions: [ 70 { 71 subscribe: { 72 channel: "BenchmarkChannel" 73 } 74 }, 75 { 76 receive: { 77 channel: "BenchmarkChannel", 78 data: { 79 message: "hello", 80 action: "broadcast" 81 } 82 } 83 } 84 ] 85 } 86 }, 87 { 88 client: { 89 protocol: "action_cable", 90 name: "another_subscriber", 91 connection_options: { 92 url: "http://localhost:8082/cable" 93 }, 94 actions: [ 95 { 96 subscribe: { 97 channel: "BenchmarkChannel" 98 } 99 }, 100 { 101 receive: { 102 channel: "BenchmarkChannel", 103 data: { 104 message: "hello", 105 action: "broadcast" 106 } 107 } 108 } 109 ] 110 } 111 } 112 ] 113 114 TEST_COMMAND = <<~CMD 115 bundle exec wsdirector ws://localhost:8080/cable -i #{scenario.to_json} 116 CMD 117 118 # NATS super-cluster may take longer to fully connect 119 retrying(delay: 2) do 120 run :wsdirector, TEST_COMMAND 121 122 result = stdout(:wsdirector) 123 124 unless result.include?("Group publisher: 1 clients, 0 failures") && 125 result.include?("Group subscriber: 1 clients, 0 failures") && 126 result.include?("Group another_subscriber: 1 clients, 0 failures") 127 fail "Unexpected scenario result:\n#{result}" 128 end 129 end