How to use testFailures method of is Package

Best Is code snippet using is.testFailures

performance_test.go

Source:performance_test.go Github

copy

Full Screen

...263	mem99Pct := float64(memHistogram.Percentile(0.99)) / (1024 * 1024)264	printStatsForHistogram(memHistogram, fmt.Sprintf("Server mem usage for %s", label), "MB", 1024*1024)265	cpu99Pct := float64(cpuHistogram.Percentile(0.99)) / (1000 * 1000)266	printStatsForHistogram(cpuHistogram, fmt.Sprintf("Server CPU usage for %s", label), "%", 1000*1000)267	testFailures := []error{}268	marginOfError := 0.05269	requestsPerSecondThreshold := int((1.0 - marginOfError) * float64(p.RequestsPerSecond))270	if (successCount / durationInSeconds) < requestsPerSecondThreshold {271		testFailures = append(testFailures,272			fmt.Errorf("Handled requests %d per second was lower than %d benchmark", successCount/durationInSeconds, requestsPerSecondThreshold))273	}274	if successCount < len(results) {275		testFailures = append(testFailures,276			fmt.Errorf("Success ratio %d/%d, giving percentage %.3f%%, is too low", successCount, len(results), 100*successPercentage))277	}278	if medTime > p.TimeThresholds.Med {279		testFailures = append(testFailures,280			fmt.Errorf("Median response time of %.3fms was greater than %.3fms benchmark",281				float64(medTime)/float64(time.Millisecond),282				float64(p.TimeThresholds.Med)/float64(time.Millisecond)))283	}284	if pct90Time > p.TimeThresholds.Pct90 {285		testFailures = append(testFailures,286			fmt.Errorf("90th percentile response time of %.3fms was greater than %.3fms benchmark",287				float64(pct90Time)/float64(time.Millisecond),288				float64(p.TimeThresholds.Pct90)/float64(time.Millisecond)))289	}290	if pct95Time > p.TimeThresholds.Pct95 {291		testFailures = append(testFailures,292			fmt.Errorf("95th percentile response time of %.3fms was greater than %.3fms benchmark",293				float64(pct95Time)/float64(time.Millisecond),294				float64(p.TimeThresholds.Pct95)/float64(time.Millisecond)))295	}296	if cpu99Pct > p.VitalsThresholds.CPUPct99 {297		testFailures = append(testFailures,298			fmt.Errorf("99th percentile server CPU usage of %.2f%% was greater than %.2f%% ceiling", cpu99Pct, p.VitalsThresholds.CPUPct99))299	}300	if mem99Pct > p.VitalsThresholds.MemPct99 {301		testFailures = append(testFailures,302			fmt.Errorf("99th percentile server memory usage of %.2fMB was greater than %.2fMB ceiling", mem99Pct, p.VitalsThresholds.MemPct99))303	}304	if memMax > p.VitalsThresholds.MemMax {305		testFailures = append(testFailures,306			fmt.Errorf("Max server memory usage of %.2fMB was greater than %.2fMB ceiling", memMax, p.VitalsThresholds.MemMax))307	}308	p.postDatadogEvent("Finishing performance test", "")309	Expect(testFailures).To(BeEmpty())310}311func (p *PerformanceTest) getProcCpu() *sigar.ProcCpu {312	if p.procCpu == nil {313		p.procCpu = &sigar.ProcCpu{}314	}315	return p.procCpu316}317func (p *PerformanceTest) getProcessCPU() float64 {318	pCpu := p.getProcCpu()319	err := pCpu.Get(p.ServerPID)320	if err != nil {321		panic(err.Error())322	}323	return pCpu.Percent * 100.0...

Full Screen

Full Screen

backend_test.go

Source:backend_test.go Github

copy

Full Screen

...12var (13	connected         = true14	connectCalled     = false15	buildQueuesCalled = false16	testFailures      = false17	createBadMessages = false18	invalidMessages   = false19	makeDeliveries    = true20)21type TestBackend struct {22	config         Config23	messageChannel chan worker.Message24}25type TestRabbitBackend struct {26	connected bool27}28type TestRabbitChannel struct{}29func NewTestRabbitBackend() TestRabbitBackend {30	return TestRabbitBackend{31		connected: true,32	}33}34// GetMessages gets a message from the configured backend35func (b TestBackend) GetMessages() (chan *worker.Message, error) {36	wmchan := make(chan *worker.Message, 1)37	return wmchan, nil38}39func (b TestBackend) getChannelFromAMQPBackend() (<-chan libamqp.Delivery, error) {40	log.Infof("Sending message in getChannel")41	deliveries := make(chan libamqp.Delivery, 1)42	deliveries <- libamqp.Delivery{43		ContentType: "application/json",44		Exchange:    "test",45		RoutingKey:  "test",46		Body: []byte(`{47			"id": "01234",48			"method": "get",49			"payload": "test"}`),50	}51	return deliveries, nil52}53func (b TestBackend) processAmqpDelivery(d libamqp.Delivery) (worker.Message, error) {54	message := worker.Message{}55	return message, nil56}57func (r TestRabbitBackend) Channel() amqp.RabbitChanneller {58	return &TestRabbitChannel{}59}60func (r TestRabbitBackend) Connect(uri string) error {61	connectCalled = true62	if testFailures {63		return fmt.Errorf("Test Failure")64	}65	return nil66}67func (r TestRabbitBackend) Connected() bool {68	return connected69}70func (r TestRabbitBackend) BuildQueues(reliable bool) error {71	buildQueuesCalled = true72	if testFailures {73		return fmt.Errorf("Test Failure")74	}75	return nil76}77func (t TestRabbitChannel) Consume(string, string, bool, bool, bool, bool, libamqp.Table) (<-chan libamqp.Delivery, error) {78	log.Infof("In test consume")79	if !testFailures {80		log.Infof("after test failures")81		if createBadMessages {82			log.Infof("after createBadMessages")83			deliveries := make(chan libamqp.Delivery, 10)84			go func() {85				log.Infof("makeDeliveries: %b", makeDeliveries)86				if makeDeliveries {87					log.Infof("Making bad messages")88					for i := 0; i < 10; i++ {89						log.Infof("Made %d messages", i)90						if !invalidMessages {91							log.Infof("Making invalid json message")92							deliveries <- libamqp.Delivery{93								ContentType: "application/json",94								Body:        []byte(`{"bad": "message"}`),95							}96						} else {97							log.Infof("Making invalid message")98							deliveries <- libamqp.Delivery{99								ContentType: "application/json",100								Body:        []byte(`really bad`),101							}102						}103					}104				}105				return106			}()107			time.Sleep(1000 * time.Millisecond)108			log.Infof("Returning from Consume")109			return deliveries, nil110		}111		log.Infof("making deliveries of size 10")112		deliveries := make(chan libamqp.Delivery, 10)113		go func() {114			log.Infof("makeDeliveries: %b", makeDeliveries)115			if makeDeliveries {116				for i := 0; i < 10; i++ {117					log.Infof("Made %d messages", i)118					deliveries <- libamqp.Delivery{119						ContentType: "application/json",120						Body: []byte(`{121							"id": "01234",122							"method": "get",123							"payload": "test"}`),124					}125				}126			}127			return128		}()129		time.Sleep(1000 * time.Millisecond)130		return deliveries, nil131	}132	return nil, fmt.Errorf("Test Failure")133}134func (t TestRabbitChannel) ExchangeDeclare(string, string, bool, bool, bool, bool, libamqp.Table) error {135	return nil136}137func (t TestRabbitChannel) QueueDeclare(string, bool, bool, bool, bool, libamqp.Table) (libamqp.Queue, error) {138	return libamqp.Queue{}, nil139}140func (t TestRabbitChannel) Qos(int, int, bool) error {141	return nil142}143func (t TestRabbitChannel) QueueBind(string, string, string, bool, libamqp.Table) error {144	return nil145}146func TestNewBackend(t *testing.T) {147	backend := NewBackend()148	assert.NotNil(t, backend)149}150func TestBackendSetup(t *testing.T) {151	backend := NewBackend()152	backend.RabbitBackend = NewTestRabbitBackend()153	connectCalled = false154	assert.Nil(t, backend.Setup())155	assert.True(t, connectCalled)156}157func TestBackendInitialize(t *testing.T) {158	backend := NewBackend()159	backend.RabbitBackend = NewTestRabbitBackend()160	buildQueuesCalled = false161	assert.Nil(t, backend.Initialize())162	assert.True(t, buildQueuesCalled)163}164func TestBackendInitializeFailure(t *testing.T) {165	backend := NewBackend()166	backend.RabbitBackend = NewTestRabbitBackend()167	buildQueuesCalled = false168	testFailures = true169	error := backend.Initialize()170	assert.NotNil(t, error)171	assert.True(t, buildQueuesCalled)172	assert.Equal(t, "Rabbitmq Build Queue Error: Test Failure.\n", error.Error(), fmt.Sprintf("'%s' is supposed to equal '%s'", error.Error(), "Rabbitmq Build Queue Error: Test Failure.\n"))173}174func TestBackendInitializeWhenNotConnected(t *testing.T) {175	backend := NewBackend()176	backend.RabbitBackend = NewTestRabbitBackend()177	connected = false178	buildQueuesCalled = false179	defer func() {180		connected = true181	}()182	testFailures = false183	error := backend.Initialize()184	assert.NotNil(t, error)185}186func TestGetChannelFromAMQPBackend(t *testing.T) {187	backend := NewBackend()188	backend.RabbitBackend = NewTestRabbitBackend()189	buildQueuesCalled = false190	testFailures = false191	deliveries, error := backend.getChannelFromAMQPBackend()192	assert.Nil(t, error)193	assert.NotNil(t, deliveries)194	buildQueuesCalled = false195	testFailures = true196	deliveries, error = backend.getChannelFromAMQPBackend()197	assert.NotNil(t, error)198	assert.Nil(t, deliveries)199}200func TestGetMessagesWithoutMessages(t *testing.T) {201	var (202		err error203	)204	log.Infof("Test 1")205	backend := NewBackend()206	backend.RabbitBackend = NewTestRabbitBackend()207	makeDeliveries = false208	testFailures = false209	_, _, err = backend.GetMessages()210	assert.Nil(t, err)211}212func TestGetMessagesWithMessages(t *testing.T) {213	var (214		err      error215		errors   chan error216		messages chan *worker.Message217	)218	log.Infof("Test 2")219	backend := NewBackend()220	backend.RabbitBackend = NewTestRabbitBackend()221	makeDeliveries = true222	testFailures = false223	messages, errors, err = backend.GetMessages()224	assert.Nil(t, err)225	exit := false226	for {227		select {228		case msg := <-messages:229			log.Infof("Got messages from backend: %s", msg)230		case err := <-errors:231			log.Infof("Got error: %s", err.Error())232		default:233			if backend.MessageCount == 10 {234				log.Infof("Breaking test loop")235				backend.quit <- true236				exit = true237				<-backend.done238				break239			}240			log.Infof("MessageCount: %d", backend.MessageCount)241			time.Sleep(1 * time.Second)242		}243		if exit {244			break245		}246	}247}248func TestGetMessagesWithFailures(t *testing.T) {249	var (250		err error251	)252	log.Infof("Test 3")253	backend := NewBackend()254	backend.RabbitBackend = NewTestRabbitBackend()255	makeDeliveries = false256	testFailures = true257	_, _, err = backend.GetMessages()258	assert.NotNil(t, err)259}260func TestGetBadJsonMessages(t *testing.T) {261	var messages chan *worker.Message262	backend := NewBackend()263	backend.RabbitBackend = NewTestRabbitBackend()264	makeDeliveries = true265	testFailures = false266	createBadMessages = true267	exit := false268	_, errors, err := backend.GetMessages()269	assert.Nil(t, err)270	errorCount := 0271	msgCount := 0272	for {273		select {274		case msg := <-messages:275			msgCount++276			log.Infof("Got messages from backend: %s", msg)277		case err := <-errors:278			errorCount++279			log.Infof("Got error: %s", err.Error())280		default:281			if backend.MessageCount == 10 {282				backend.quit <- true283				<-backend.done284				exit = true285				break286			}287			log.Infof("MessageCount: %d", backend.MessageCount)288			time.Sleep(1 * time.Second)289		}290		if exit {291			break292		}293	}294	assert.Exactly(t, 10, errorCount)295	assert.Exactly(t, 0, msgCount)296}297func TestGetBadMessages(t *testing.T) {298	var messages chan *worker.Message299	backend := NewBackend()300	backend.RabbitBackend = NewTestRabbitBackend()301	makeDeliveries = true302	testFailures = false303	createBadMessages = true304	invalidMessages = true305	exit := false306	_, errors, err := backend.GetMessages()307	assert.Nil(t, err)308	errorCount := 0309	msgCount := 0310	for {311		select {312		case msg := <-messages:313			msgCount++314			log.Infof("Got messages from backend: %s", msg)315		case err := <-errors:316			errorCount++317			log.Infof("Got error: %s", err.Error())318		default:319			if errorCount == 10 {320				backend.quit <- true321				<-backend.done322				exit = true323				break324			}325			log.Infof("MessageCount: %d", backend.MessageCount)326			time.Sleep(1 * time.Second)327		}328		if exit {329			break330		}331	}332	assert.Exactly(t, 10, errorCount)333	assert.Exactly(t, 0, msgCount)334}335func TestGetMessagesWhenNotConnected(t *testing.T) {336	backend := NewBackend()337	backend.RabbitBackend = NewTestRabbitBackend()338	connected = false339	defer func() {340		connected = true341	}()342	makeDeliveries = false343	testFailures = false344	log.Errorf("About to get messages...")345	_, _, error := backend.GetMessages()346	assert.NotNil(t, error)347}...

Full Screen

Full Screen

deploy.go

Source:deploy.go Github

copy

Full Screen

...69		ErrorAndExit(deployErr.Error())70	}71	problems := result.Details.ComponentFailures72	successes := result.Details.ComponentSuccesses73	testFailures := result.Details.RunTestResult.TestFailures74	testSuccesses := result.Details.RunTestResult.TestSuccesses75	codeCoverageWarnings := result.Details.RunTestResult.CodeCoverageWarnings76	if len(successes) > 0 {77		fmt.Printf("\nSuccesses - %d\n", len(successes)-1)78		for _, success := range successes {79			if success.FullName != "package.xml" {80				verb := "unchanged"81				if success.Changed {82					verb = "changed"83				} else if success.Deleted {84					verb = "deleted"85				} else if success.Created {86					verb = "created"87				}88				fmt.Printf("\t%s: %s\n", success.FullName, verb)89			}90		}91	}92	fmt.Printf("\nTest Successes - %d\n", len(testSuccesses))93	for _, failure := range testSuccesses {94		fmt.Printf("  [PASS]  %s::%s\n", failure.Name, failure.MethodName)95	}96	if len(problems) > 0 {97		fmt.Printf("\nFailures - %d\n", len(problems))98		for _, problem := range problems {99			if problem.FullName == "" {100				fmt.Println(problem.Problem)101			} else {102				if byName {103					fmt.Printf("ERROR with %s, line %d\n %s\n", problem.FullName, problem.LineNumber, problem.Problem)104				} else {105					fname, found := namePaths[problem.FullName]106					if !found {107						fname = problem.FullName108					}109					fmt.Printf("\"%s\", line %d: %s %s\n", fname, problem.LineNumber, problem.ProblemType, problem.Problem)110				}111			}112		}113	}114	fmt.Printf("\nTest Failures - %d\n", len(testFailures))115	for _, failure := range testFailures {116		fmt.Printf("\n  [FAIL]  %s::%s: %s\n", failure.Name, failure.MethodName, failure.Message)117		fmt.Println(failure.StackTrace)118	}119	if len(codeCoverageWarnings) > 0 {120		fmt.Printf("\nCode Coverage Warnings - %d\n", len(codeCoverageWarnings))121		for _, warning := range codeCoverageWarnings {122			fmt.Printf("\n %s: %s\n", warning.Name, warning.Message)123		}124	}125	// Handle notifications126	desktop.NotifySuccess("push", len(problems) == 0)127	if len(problems) > 0 {128		err = errors.New("Some components failed deployment")129	} else if len(testFailures) > 0 {130		err = errors.New("Some tests failed")131	} else if !result.Success {132		err = errors.New(fmt.Sprintf("Status: %s", result.Status))133	}134	return135}136// Deploy a previously create package. This is used for "force push package". In this case the137// --path flag should be pointing to a zip file that may or may not have come from a different138// org altogether139func DeployPackage(resourcepaths []string, opts *ForceDeployOptions) {140	force, _ := ActiveForce()141	for _, name := range resourcepaths {142		zipfile, err := ioutil.ReadFile(name)143		result, err := force.Metadata.DeployZipFile(force.Metadata.MakeDeploySoap(*opts), zipfile)...

Full Screen

Full Screen

testFailures

Using AI Code Generation

copy

Full Screen

1func main() {2    is := is.New(t)3    is.TestFailures()4}5func main() {6    is := is.New(t)7    is.TestFailures()8}9func main() {10    is := is.New(t)11    is.TestFailures()12}13func main() {14    is := is.New(t)15    is.TestFailures()16}17func main() {18    is := is.New(t)19    is.TestFailures()20}21func main() {22    is := is.New(t)23    is.TestFailures()24}25func main() {26    is := is.New(t)27    is.TestFailures()28}29func main() {30    is := is.New(t)31    is.TestFailures()32}33func main() {34    is := is.New(t)35    is.TestFailures()36}37func main() {38    is := is.New(t)39    is.TestFailures()40}41func main() {42    is := is.New(t)43    is.TestFailures()44}45func main() {46    is := is.New(t)47    is.TestFailures()48}49func main() {50    is := is.New(t)51    is.TestFailures()52}53func main() {54    is := is.New(t)55    is.TestFailures()

Full Screen

Full Screen

testFailures

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3    is.testFailures()4}5import "fmt"6func main() {7    is.testFailures()8}9import "fmt"10func main() {11    is.testFailures()12}13import "fmt"14func main() {15    is.testFailures()16}17import "fmt"18func main() {19    is.testFailures()20}21import "fmt"22func main() {23    is.testFailures()24}25import "fmt"26func main() {27    is.testFailures()28}29import "fmt"30func main() {31    is.testFailures()32}33import "fmt"34func main() {35    is.testFailures()36}37import "fmt"38func main() {39    is.testFailures()40}41import "fmt"42func main() {43    is.testFailures()44}45import "fmt"46func main() {47    is.testFailures()48}

Full Screen

Full Screen

testFailures

Using AI Code Generation

copy

Full Screen

1import (2func main() {3    if termutil.Isatty(0) {4        fmt.Println("stdin is a tty")5    } else {6        fmt.Println("stdin is not a tty")7    }8}

Full Screen

Full Screen

testFailures

Using AI Code Generation

copy

Full Screen

1import (2func main() {3    fmt.Println("Hello, playground")4    t := testing.T{}5    t.Error("This is an error")6    t.Error("This is another error")7    t.Error("This is yet another error")8    fmt.Println(t.Failed())9    fmt.Println(t.Failures())10}11[{This is an error} {This is another error} {This is yet another error}]12import (13func main() {14    fmt.Println("Hello, playground")15    t := testing.T{}16    t.Fail("This is a failure", false)17    fmt.Println(t.Failed())18    fmt.Println(t.Failures())19}

Full Screen

Full Screen

testFailures

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println(test.TestFailures())4}5import "fmt"6type Test struct {7}8func TestFailures() string {9	tests = append(tests, Test{Name: "test1"})10	tests = append(tests, Test{Name: "test2"})11	tests = append(tests, Test{Name: "test3"})12	tests = append(tests, Test{Name: "test4"})13	tests = append(tests, Test{Name: "test5"})14	tests = append(tests, Test{Name: "test6"})15	tests = append(tests, Test{Name: "test7"})16	tests = append(tests, Test{Name: "test8"})17	tests = append(tests, Test{Name: "test9"})18	tests = append(tests, Test{Name: "test10"})19	tests = append(tests, Test{Name: "test11"})20	tests = append(tests, Test{Name: "test12"})21	tests = append(tests, Test{Name: "test13"})22	tests = append(tests, Test{Name: "test14"})23	tests = append(tests, Test{Name: "test15"})24	tests = append(tests, Test{Name: "test16"})25	tests = append(tests, Test{Name: "test17"})26	tests = append(tests, Test{Name: "test18"})27	tests = append(tests, Test{Name: "test19"})28	tests = append(tests, Test{Name: "test20"})29	tests = append(tests, Test{Name: "test21"})30	tests = append(tests, Test{Name: "test22"})31	tests = append(tests, Test{Name: "test23"})32	tests = append(tests, Test{Name: "test24"})33	tests = append(tests, Test{Name: "test25"})34	tests = append(tests, Test{Name: "test26"})35	tests = append(tests, Test{Name: "test27"})36	tests = append(tests, Test{Name: "test28"})37	tests = append(tests, Test{Name: "test29"})38	tests = append(tests, Test{Name: "test30"})39	tests = append(tests, Test{Name: "test31"})40	tests = append(tests, Test{Name: "test32"})41	tests = append(tests, Test{Name: "test33"})42	tests = append(tests, Test{Name: "

Full Screen

Full Screen

testFailures

Using AI Code Generation

copy

Full Screen

1import (2func TestFailures(t *testing.T) {3	testFailures(t)4}5func testFailures(t *testing.T) {6	var tests = []struct {7		a        interface{}8		b        interface{}9	}{10		{1, 2, true},11		{1, 1, false},12		{1.0, 2.0, true},13		{1.0, 1.0, false},14		{1, 1.0, true},15		{1.0, 1, true},16		{"1", "2", true},17		{"1", "1", false},18		{true, false, true},19		{false, false, false},20		{nil, nil, false},21		{nil, 1, true},22		{1, nil, true},23		{[]int{1, 2}, []int{1, 2}, false},24		{[]int{1, 2}, []int{1, 2, 3}, true},25		{[]int{1, 2, 3}, []int{1, 2}, true},26		{[]int{1, 2}, []int{2, 1}, true},27		{[]int{1, 2, 3}, []int{1, 2, 3}, false},28		{[]int{1, 2, 3}, []int{1, 2, 3, 4}, true},29		{[]int{1, 2, 3, 4}, []int{1, 2, 3}, true},30		{[]int{1, 2, 3}, []int{3, 2, 1}, true},31		{[]int{1, 2, 3}, []int{1, 3, 2}, true},32		{[]int{1, 2, 3}, []int{2, 1, 3}, true},33		{[]int{1, 2, 3}, []int{2, 3, 1}, true},34		{[]int{1, 2

Full Screen

Full Screen

testFailures

Using AI Code Generation

copy

Full Screen

1import "fmt"2type is struct {3}4func (i *is) testFailures() {5    fmt.Println("Is class testFailures method")6}7type has struct {8}9func (h *has) testFailures() {10    fmt.Println("Has class testFailures method")11}12func main() {13    h := has{}14    h.testFailures()15    h.is.testFailures()16}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful