<commit_before>package testStrategies

import (
	"fmt"
	log "github.com/Sirupsen/logrus"
	"github.com/xtracdev/automated-perf-test/perfTestUtils"
	"sync"
	"sync/atomic"
	"time"
)




//----- ExecuteTestSuiteWrapper ----------------------------------------------
func ExecuteTestSuiteWrapper(
			testSuite *TestSuite,
			configurationSettings *perfTestUtils.Config,
			startTime time.Time,
) map[string][]int64 {
	allServicesResponseTimesMap := make(map[string][]int64, 0)
	testSuiteResponseTimesChan := make(chan []map[string]int64, 1)
	var suiteWaitGroup sync.WaitGroup

	// Variables to track total current TPS across all threads.
	// We'll use an unsigned integer to represent our (always-positive) counter,
	// and use a wait group from the sync package to track a concurrent counter.
	var curOps uint64 = 0
	quitShowTPSChan := make(chan bool)

	suiteWaitGroup.Add(configurationSettings.ConcurrentUsers)
	for i := 0; i < configurationSettings.ConcurrentUsers; i++ {
		go executeTestSuite(testSuiteResponseTimesChan, testSuite, configurationSettings, i, GlobalsLockCounter, &curOps)
		go aggregateSuiteResponseTimes(testSuiteResponseTimesChan, allServicesResponseTimesMap, &suiteWaitGroup)
	}

	// Display the ongoing TPS to log.Info based on period specified in configurationSettings.TPSFreq:
	go showCurrentTPS(quitShowTPSChan, &curOps, startTime, configurationSettings)

	suiteWaitGroup.Wait()
	quitShowTPSChan <- true

	return allServicesResponseTimesMap
}




//----- executeTestSuite ------------------------------------------------------
func executeTestSuite(
			testSuiteResponseTimesChan chan []map[string]int64,
			testSuite *TestSuite,
			configurationSettings *perfTestUtils.Config,
			userId int,
			globalsMap GlobalsMaps,
			curOps *uint64,
) {
	log.Info("Test Suite started")

	allSuiteResponseTimes := make([]map[string]int64, 0)
	uniqueTestRunId := ""
	for i := 0; i < configurationSettings.NumIterations; i++ {
		// Run all services of the test suite NumIterations of times.
		uniqueTestRunId = fmt.Sprintf("User%dIter%d", userId, i)
		testSuiteResponseTimes := make(map[string]int64)

		for _, testDefinition := range testSuite.TestCases {
			log.Info("Test case: [", testDefinition.TestName, "] UniqueRunID: [", uniqueTestRunId, "]")

			targetHost, targetPort := determineHostandPortforRequest(testDefinition, configurationSettings)
			responseTime := testDefinition.BuildAndSendRequest(configurationSettings.RequestDelay, targetHost, targetPort, uniqueTestRunId, globalsMap)
			testSuiteResponseTimes[testDefinition.TestName] = responseTime

			// Increment the global ops counter
			atomic.AddUint64( curOps, 1 )
		}

		allSuiteResponseTimes = append(allSuiteResponseTimes, testSuiteResponseTimes)

		globalsMap.Lock()
		globalsMap.m[uniqueTestRunId] = nil
		globalsMap.Unlock()
	}<commit_msg>Fixed indent mistake.<commit_after>package testStrategies

import (
	"fmt"
	log "github.com/Sirupsen/logrus"
	"github.com/xtracdev/automated-perf-test/perfTestUtils"
	"sync"
	"sync/atomic"
	"time"
)




//----- ExecuteTestSuiteWrapper ----------------------------------------------
func ExecuteTestSuiteWrapper(
		testSuite *TestSuite,
		configurationSettings *perfTestUtils.Config,
		startTime time.Time,
) map[string][]int64 {
	allServicesResponseTimesMap := make(map[string][]int64, 0)
	testSuiteResponseTimesChan := make(chan []map[string]int64, 1)
	var suiteWaitGroup sync.WaitGroup

	// Variables to track total current TPS across all threads.
	// We'll use an unsigned integer to represent our (always-positive) counter,
	// and use a wait group from the sync package to track a concurrent counter.
	var curOps uint64 = 0
	quitShowTPSChan := make(chan bool)

	suiteWaitGroup.Add(configurationSettings.ConcurrentUsers)
	for i := 0; i < configurationSettings.ConcurrentUsers; i++ {
		go executeTestSuite(testSuiteResponseTimesChan, testSuite, configurationSettings, i, GlobalsLockCounter, &curOps)
		go aggregateSuiteResponseTimes(testSuiteResponseTimesChan, allServicesResponseTimesMap, &suiteWaitGroup)
	}

	// Display the ongoing TPS to log.Info based on period specified in configurationSettings.TPSFreq:
	go showCurrentTPS(quitShowTPSChan, &curOps, startTime, configurationSettings)

	suiteWaitGroup.Wait()
	quitShowTPSChan <- true

	return allServicesResponseTimesMap
}




//----- executeTestSuite ------------------------------------------------------
func executeTestSuite(
		testSuiteResponseTimesChan chan []map[string]int64,
		testSuite *TestSuite,
		configurationSettings *perfTestUtils.Config,
		userId int,
		globalsMap GlobalsMaps,
		curOps *uint64,
) {
	log.Info("Test Suite started")

	allSuiteResponseTimes := make([]map[string]int64, 0)
	uniqueTestRunId := ""
	for i := 0; i < configurationSettings.NumIterations; i++ {
		// Run all services of the test suite NumIterations of times.
		uniqueTestRunId = fmt.Sprintf("User%dIter%d", userId, i)
		testSuiteResponseTimes := make(map[string]int64)

		for _, testDefinition := range testSuite.TestCases {
			log.Info("Test case: [", testDefinition.TestName, "] UniqueRunID: [", uniqueTestRunId, "]")

			targetHost, targetPort := determineHostandPortforRequest(testDefinition, configurationSettings)
			responseTime := testDefinition.BuildAndSendRequest(configurationSettings.RequestDelay, targetHost, targetPort, uniqueTestRunId, globalsMap)
			testSuiteResponseTimes[testDefinition.TestName] = responseTime

			// Increment the global ops counter
			atomic.AddUint64( curOps, 1 )
		}

		allSuiteResponseTimes = append(allSuiteResponseTimes, testSuiteResponseTimes)

		globalsMap.Lock()
		globalsMap.m[uniqueTestRunId] = nil
		globalsMap.Unlock()
	}
{'fraction_non_alphanumeric': 0.1299414997340897, 'fraction_numerical': 0.008863676653075695, 'mean_word_length': 4.482993197278912, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1194786', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1621, 'n_words': 384}