#!/bin/sh

# Checking if the failover strategy  for multiple "connect" targets.
# The round robin (rr) strategy ensures fair load distribution.
# At least one connection with each service is expected.

. $(dirname $0)/../test_library

start() {
  ../../src/stunnel -fd 0 <<EOT
  debug = debug
  syslog = no
  pid = ${result_path}/stunnel.pid
  output = ${result_path}/stunnel.log
  failover = rr

  [client]
  client = yes
  accept = 127.0.0.1:${http1}
  connect = 127.0.0.1:${https1}
  connect = 127.0.0.1:${https2}
  connect = 127.0.0.1:${https3}

  [server_1]
  accept = 127.0.0.1:${https1}
  connect = 127.0.0.1:${http_nc}
  cert = ${script_path}/certs/server_cert.pem

  [server_2]
  accept = 127.0.0.1:${https2}
  connect = 127.0.0.1:${http_nc}
  cert = ${script_path}/certs/server_cert.pem

  [server_3]
  accept = 127.0.0.1:${https3}
  connect = 127.0.0.1:${http_nc}
  cert = ${script_path}/certs/server_cert.pem
EOT
}

test_log_for "039_failover_rr" "rr" "0" "$1" "$2" "$3" 2>> "stderr.log"
exit $?
