github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/testing/ddev-perf-test.sh (about)

     1  #!/bin/bash
     2  
     3  
     4  BLUE=$(tput setaf 4)
     5  YELLOW=$(tput setaf 3)
     6  RESET=$(tput sgr0)
     7  
     8  TIMECMD=gtime
     9  command -v $TIMECMD >/dev/null 2>&1 || { echo >&2 "please install gnu time with \"brew install gnu-time\"."; exit 1; }
    10  TIMEFMT='-f %e'
    11  TIMEIT="$TIMECMD $TIMEFMT -o time.out"
    12  CURLIT='curl  -o /dev/null --fail -sfL -w %{time_total}'
    13  unset DDEV_DEBUG
    14  
    15  PROFILE=standard
    16  
    17  export tmpfolder=/tmp
    18  # Docker can't mount on straight /tmp
    19  if [ $(uname -s) = "Darwin" ] ; then
    20  	tmpfolder=/private/tmp
    21  fi
    22  # OSX TMPDIR comes out in /var/... which isn't compatible with mounts on docker by default
    23  cd $tmpfolder
    24  
    25  # Parallel arrays to describe features of the sites to test.
    26  # Not using associative arrays because they only appear in bash 4
    27  sites=(d7perf kickperf d8perf)
    28  types=(drupal7 drupal7 drupal8)
    29  downloads=(drupal-7.54 commerce_kickstart-7.x-2.45 drupal-8.3.2)
    30  
    31  # Alternate approach for testing just one site
    32  #sites=(d8perf) types=(drupal8) downloads=(drupal-8.3.2)
    33  #sites=(d7perf) types=(drupal7) downloads=(drupal-7.54)
    34  
    35  for ((i=0; i<${#sites[@]}; ++i)); do
    36  	site=${sites[$i]}
    37  	base_url=http://$site.ddev.local
    38  
    39  
    40  	if [ ! -d "$site" ] ; then
    41  		drush dl -y ${downloads[$i]} --drupal-project-rename=$site > /dev/null 2>&1
    42  	fi
    43  
    44  	PROFILE=standard
    45  
    46  	cd "$tmpfolder/$site";
    47      echo
    48      echo "Starting $site tests using profile $PROFILE"
    49  
    50  	# Start with fresh cookies file
    51  	cookiefile=$site.cookies.txt
    52  	rm -f $cookiefile
    53  	log=$site.log.txt
    54  	rm -f $log
    55  
    56  	# Create the config.yml
    57      mkdir -p .ddev
    58      cat <<END >.ddev/config.yaml
    59  APIVersion: 1
    60  docroot: ""
    61  type: ${types[$i]}
    62  END
    63  
    64  	# Remove any site that is already running, but don't both reporting or worrying about it.
    65  	ddev rm -y >>$log 2>&1 || true
    66  	chmod -R ugo+w sites/default && rm -f sites/default/settings.php
    67  
    68      $TIMEIT ddev start >$log 2>&1
    69      echo "${BLUE}$site: ddev start: $(cat time.out) ${RESET}"
    70  
    71      elapsed=$($CURLIT  $base_url)
    72      echo "${BLUE}$site: curl not-installed site ($?): $elapsed${RESET}"
    73  
    74  	# Normally use the commerce_kickstart profile unless profile is set to "minimal" for testing speedup.
    75      if [[ "$site" = "kickperf" && "$PROFILE" != "minimal" ]]; then
    76      	PROFILE=commerce_kickstart
    77  	fi
    78  
    79  	# drush si - if it fails we continue to next site.
    80  	$TIMEIT ddev exec drush si $PROFILE -y --db-url=mysql://db:db@db/db >>$log 2>&1 || (echo "Failed drush si" && continue)
    81      echo "${BLUE}$site: drush site-install: $(cat time.out) ${RESET}"
    82  
    83      elapsed=$($CURLIT -fL $base_url)
    84      echo "${BLUE}$site: anon curl ($?) after site install: $elapsed ${RESET}"
    85  
    86      elapsed=$($CURLIT -fL $base_url)
    87      echo "${BLUE}$site: anon curl ($?) again after site install: $elapsed ${RESET}"
    88  
    89  	$TIMEIT ddev exec drush uli -l $site.ddev.local >$site.uli.txt 2>&1 || (echo "Failed drush uli" && continue)
    90  	echo "${BLUE}$site: ddev uli: $(cat time.out) ${RESET}"
    91  
    92  	# This technique doesn't work on d8 due to some new form fields on the uli page.
    93  #	uli_url=$(cat $site.uli.txt)
    94  #	elapsed=$($CURLIT -X POST --cookie-jar $cookiefile -H 'content-type: multipart/form-data' -F form_id=user_pass_reset  $uli_url)
    95  #    echo "${BLUE}$site: uli login $uli_url ($?): $elapsed ${RESET}"
    96  
    97  	# Create user adminuser password adminuser, in administrator group
    98  	# Note that this doesn't work with the 'minimal' profile since there is no 'administrator' role created.
    99      ddev exec drush ucrt adminuser --password=adminuser >>$log 2>&1 || echo "Failed drush ucrt"
   100      ddev exec drush urol administrator adminuser >>$log 2>&1 || echo "Failed drush urol"
   101  
   102  	form=user_login
   103  	if [ ${types[i]} = "drupal8" ] ; then
   104  		   form=user_login_form
   105  	fi
   106  	elapsed=$($CURLIT -X POST --cookie-jar $cookiefile -H 'content-type: multipart/form-data' -F pass=adminuser -F name=adminuser -F form_id=$form  $base_url/user/login)
   107      echo "${BLUE}$site: login ($?): $elapsed ${RESET}"
   108  
   109      elapsed=$($CURLIT --cookie $cookiefile $base_url)
   110      echo "${BLUE}$site: front authenticated ($?): $elapsed ${RESET}"
   111  
   112      elapsed=$($CURLIT --cookie $cookiefile $base_url)
   113      echo "${BLUE}$site: front authenticated again ($?): $elapsed ${RESET}"
   114  
   115      elapsed=$($CURLIT --cookie $cookiefile $base_url/user/1)
   116      echo "${BLUE}$site: user/1 ($?): $elapsed ${RESET}"
   117  
   118      elapsed=$($CURLIT --cookie $cookiefile $base_url/user/1)
   119      echo "${BLUE}$site: user/1 again ($?): $elapsed ${RESET}"
   120  
   121      elapsed=$($CURLIT --cookie $cookiefile $base_url/admin/modules)
   122      echo "${BLUE}$site: admin/modules ($?): $elapsed ${RESET}"
   123  
   124      $TIMEIT ddev exec drush pml >>$log 2>&1 || echo "Failed drush pml"
   125      echo "${BLUE}$site: drush pml: $(cat time.out) ${RESET}"
   126  
   127      echo "Tests completed for $site."
   128  #   echo "Removing..."
   129  # 	ddev rm -y >>$log 2>&1
   130  
   131      cd $tmpfolder
   132  done