#!/bin/sh

# Checking if disable delay option works properly when the session is resumed.
# This option delays DNS lookup for the connect option.
# Exactly "2" "accepted: new session negotiated" logs for [server_1]
# and [server_2] services are expected, because failover = rr

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

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

  delay = no
  failover = rr
  retry = yes

  [client]
  client = yes
  exec = ${script_path}/execute_read
  execArgs = execute_read ${result_path}/temp.log
  connect = 127.0.0.1:${https1}
  connect = 127.0.0.1:${https2}

  [server_1]
  accept = 127.0.0.1:${https1}
  exec = ${script_path}/execute
  execArgs = execute 044_session_nodelay
  cert = ${script_path}/certs/server_cert.pem

  [server_2]
  accept = 127.0.0.1:${https2}
  exec = ${script_path}/execute
  execArgs = execute 044_session_nodelay
  cert = ${script_path}/certs/server_cert.pem
EOT
}

if ! grep -q "FORK" "results.log"
  then
    test_log_for "044_session_nodelay" "session" "2" "$1" "$2" "$3" 2>> "stderr.log"
    exit $?
  else # the resumption of the session does not work for the FORK model
    exit_logs "044_session_nodelay" "skipped"
    exit 125
  fi
exit $?
