<commit_before>#!/bin/bash

# Copyright 2020 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script includes common functions for testing setup and teardown.
source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/e2e-tests.sh

# Default to Istio 'stable' version.
ISTIO_VERSION="stable"

# Parse our custom flags.
function parse_flags() {
  case "$1" in
    --istio-version)
      readonly ISTIO_VERSION=$2
      readonly INGRESS_CLASS="istio.ingress.networking.knative.dev"
      return 2
      ;;
  esac
  return 0
}

# Setup resources.
function test_setup() {
  echo ">> Setting up logging..."
  # Install kail if needed.
  if ! which kail > /dev/null; then
    bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$GOPATH/bin"
  fi
  # Capture all logs.
  kail > ${ARTIFACTS}/k8s.log.txt &
  local kail_pid=$!
  # Clean up kail so it doesn't interfere with job shutting down
  add_trap "kill $kail_pid || true" EXIT

  # Setting up test resources.
  echo ">> Publishing test images"
  $(dirname $0)/upload-test-images.sh || fail_test "Error uploading test images"
  echo ">> Creating test resources (test/config/)"
  ko apply ${KO_FLAGS} -f test/config/ || return 1

  # Bringing up controllers.
  echo ">> Bringing up Istio"
  echo ">> Running Istio CRD installer"
  local istio_dir=third_party/istio-${ISTIO_VERSION}
  kubectl apply -f ${istio_dir}/istio-crds.yaml || return 1
  wait_until_batch_job_complete istio-system || return 1
  echo ">> Running Istio"
  kubectl apply -f ${istio_dir}/istio-ci-no-mesh.yaml || return 1
  echo ">> Bringing up net-istio Ingress Controller"
  ko apply -f config/ || return 1

  # Wait for pods to be running.
  echo ">> Waiting for Istio components to be running..."
  wait_until_pods_running istio-system || return 1
  echo ">> Waiting for Serving components to be running..."
  wait_until_pods_running knative-serving || return 1

  # Wait for static IP to be through
  wait_for_static_ip istio-system istio-ingressgateway
}

function wait_for_static_ip() {
  local ns=$1
  local svc=$2
  local sleep_seconds=20
  local attempts=100

  STATIC_IP=""
  for try in $(seq 1 $attempts); do
    STATIC_IP=$(kubectl get svc $svc -n $ns -ojsonpath={.status.loadBalancer.ingress[0].ip})
    STATUS_CODE=""
    if [[ $STATIC_IP != "" ]]; then
      echo ">> Probing $STATIC_IP"
      STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://$STATIC_IP)
      if [[ $STATUS_CODE != "" && $STATUS_CODE != "000" ]]; then
        echo ">> $STATIC_IP is ready: prober observed HTTP $STATUS_CODE"
        return
      else
        echo ">> $STATIC_IP is not ready: prober observed HTTP $STATUS_CODE"
      fi
    else
      echo ">> Service $ns/$svc does not have an IP address."
    fi
    sleep $sleep_seconds
  done
  echo ">> Error waiting for ip address '$STATIC_IP' to be ready"
}

# Add function call to trap
# Parameters: $1 - Function to call
#             $2...$n - Signals for trap
function add_trap() {
  local cmd=$1
  shift
  for trap_signal in $@; do
    local current_trap="$(trap -p $trap_signal | cut -d\' -f2)"
    local new_cmd="($cmd)"
    [[ -n "${current_trap}" ]] && new_cmd="${current_trap};${new_cmd}"
    trap -- "${new_cmd}" $trap_signal
  done
}
<commit_msg>Use wait func from knative.dev/test-infra (#87)<commit_after>#!/bin/bash

# Copyright 2020 The Knative Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script includes common functions for testing setup and teardown.
source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/e2e-tests.sh

# Default to Istio 'stable' version.
ISTIO_VERSION="stable"

# Parse our custom flags.
function parse_flags() {
  case "$1" in
    --istio-version)
      readonly ISTIO_VERSION=$2
      readonly INGRESS_CLASS="istio.ingress.networking.knative.dev"
      return 2
      ;;
  esac
  return 0
}

# Setup resources.
function test_setup() {
  echo ">> Setting up logging..."
  # Install kail if needed.
  if ! which kail > /dev/null; then
    bash <( curl -sfL https://raw.githubusercontent.com/boz/kail/master/godownloader.sh) -b "$GOPATH/bin"
  fi
  # Capture all logs.
  kail > ${ARTIFACTS}/k8s.log.txt &
  local kail_pid=$!
  # Clean up kail so it doesn't interfere with job shutting down
  add_trap "kill $kail_pid || true" EXIT

  # Setting up test resources.
  echo ">> Publishing test images"
  $(dirname $0)/upload-test-images.sh || fail_test "Error uploading test images"
  echo ">> Creating test resources (test/config/)"
  ko apply ${KO_FLAGS} -f test/config/ || return 1

  # Bringing up controllers.
  echo ">> Bringing up Istio"
  echo ">> Running Istio CRD installer"
  local istio_dir=third_party/istio-${ISTIO_VERSION}
  kubectl apply -f ${istio_dir}/istio-crds.yaml || return 1
  wait_until_batch_job_complete istio-system || return 1
  echo ">> Running Istio"
  kubectl apply -f ${istio_dir}/istio-ci-no-mesh.yaml || return 1
  echo ">> Bringing up net-istio Ingress Controller"
  ko apply -f config/ || return 1

  # Wait for pods to be running.
  echo ">> Waiting for Istio components to be running..."
  wait_until_pods_running istio-system || return 1
  echo ">> Waiting for Serving components to be running..."
  wait_until_pods_running knative-serving || return 1

  # Wait for static IP to be through
  wait_until_service_has_external_http_address istio-system istio-ingressgateway
}

# Add function call to trap
# Parameters: $1 - Function to call
#             $2...$n - Signals for trap
function add_trap() {
  local cmd=$1
  shift
  for trap_signal in $@; do
    local current_trap="$(trap -p $trap_signal | cut -d\' -f2)"
    local new_cmd="($cmd)"
    [[ -n "${current_trap}" ]] && new_cmd="${current_trap};${new_cmd}"
    trap -- "${new_cmd}" $trap_signal
  done
}

{'fraction_non_alphanumeric': 0.11636470761525998, 'fraction_numerical': 0.010016202680807188, 'mean_word_length': 3.4700460829493087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1157856', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2192, 'n_words': 733}