<commit_before>package rpc

import (
	"net/rpc"
	"strconv"

	. "github.com/onsi/ginkgo"
	coModel "github.com/open-falcon/common/model"
)

var _ = Describe("[Stress] Test Agent.ReportStatus in HBS", ginkgoJsonRpc.NeedJsonRpc(func() {
	var (
		numberOfGoRoutines int = 50
		pool               *agentPool
		routines           chan bool

		numberOfFakeAgent int = 0
	)

	checkSkipCondition := func() {
		if numberOfFakeAgent == 0 {
			Skip("Number of total request is 0. See numberOfFakeAgent in code")
		}
	}

	BeforeEach(func() {
		checkSkipCondition()

		pool = &agentPool{numberOfFakeAgent}
		routines = make(chan bool, numberOfGoRoutines)
		for i := 0; i < numberOfGoRoutines; i++ {
			routines <- true
		}
	})

	Measure("It should serve lots rpc-clients efficiently", func(b Benchmarker) {
		checkSkipCondition()
		b.Time("runtime", func() {
			for i := 0; i < numberOfFakeAgent; i++ {
				request := pool.getNextRequest(i)
				var resp coModel.SimpleRpcResponse

				<-routines

				go ginkgoJsonRpc.OpenClient(func(jsonRpcClient *rpc.Client) {
					defer func() {
						routines <- true
					}()

					err := jsonRpcClient.Call(
						"Agent.ReportStatus", request, &resp,
					)

					if err != nil || resp.Code == 1 {
						GinkgoT().Errorf("[%s] Has error: %v", request.AgentVersion, err)
					} else {
						GinkgoT().Logf("[%s/%d] Success.", request.PluginVersion, numberOfFakeAgent)
					}
				})
			}

			for i := 0; i < numberOfGoRoutines; i++ {
				<-routines
			}
		})
	}, 3)
}))

type agentPool struct {
	ringSize int
}<commit_msg>[OWL-1621] Let repeat time as a variable. Rename a variable to numberOfFakeAgents.<commit_after>package rpc

import (
	"net/rpc"
	"strconv"

	. "github.com/onsi/ginkgo"
	coModel "github.com/open-falcon/common/model"
)

var _ = Describe("[Stress] Test Agent.ReportStatus in HBS", ginkgoJsonRpc.NeedJsonRpc(func() {
	var (
		numberOfGoRoutines int = 50
		pool               *agentPool
		routines           chan bool

		numberOfFakeAgents int = 0
		numberOfSamples    int = 3
	)

	checkSkipCondition := func() {
		if numberOfFakeAgents == 0 {
			Skip("Number of total request is 0. See numberOfFakeAgents in code")
		}
	}

	BeforeEach(func() {
		checkSkipCondition()

		pool = &agentPool{numberOfFakeAgents}
		routines = make(chan bool, numberOfGoRoutines)
		for i := 0; i < numberOfGoRoutines; i++ {
			routines <- true
		}
	})

	Measure("It should serve lots rpc-clients efficiently", func(b Benchmarker) {
		checkSkipCondition()
		b.Time("runtime", func() {
			for i := 0; i < numberOfFakeAgents; i++ {
				request := pool.getNextRequest(i)
				var resp coModel.SimpleRpcResponse

				<-routines

				go ginkgoJsonRpc.OpenClient(func(jsonRpcClient *rpc.Client) {
					defer func() {
						routines <- true
					}()

					err := jsonRpcClient.Call(
						"Agent.ReportStatus", request, &resp,
					)

					if err != nil || resp.Code == 1 {
						GinkgoT().Errorf("[%s] Has error: %v", request.AgentVersion, err)
					} else {
						GinkgoT().Logf("[%s/%d] Success.", request.PluginVersion, numberOfFakeAgents)
					}
				})
			}

			for i := 0; i < numberOfGoRoutines; i++ {
				<-routines
			}
		})
	}, numberOfSamples)
}))

type agentPool struct {
	ringSize int
}
{'fraction_non_alphanumeric': 0.13271028037383178, 'fraction_numerical': 0.007476635514018692, 'mean_word_length': 3.01375, 'pattern_counts': {'":': 0, '<': 17, '<?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': '6943054', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1116, 'n_words': 258}