File: init.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.1.14%2Bdfsg-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 25,052 kB
  • sloc: ruby: 193; makefile: 98
file content (91 lines) | stat: -rw-r--r-- 2,622 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package performance

import (
	"bytes"
	"errors"
	"fmt"
	"runtime"

	"github.com/lsegal/gucumber"
	"github.com/stretchr/testify/assert"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/awserr"
	"github.com/aws/aws-sdk-go/awstesting/mock"
	"github.com/aws/aws-sdk-go/service/s3"
)

func init() {
	// Go loads all of its dependecies on compile
	gucumber.Given(`^I have loaded my SDK and its dependencies$`, func() {
	})

	// Performance
	gucumber.When(`^I create and discard (\d+) clients for each service$`, func(i1 int) {
		services := gucumber.World["services"].([]func())
		err := benchmarkTask(fmt.Sprintf("%d_create_and_discard_clients", i1), services, i1)
		gucumber.World["error"] = err
	})

	gucumber.Then(`^I should not have leaked any resources$`, func() {
		runtime.GC()
		err, ok := gucumber.World["error"].(awserr.Error)
		assert.False(gucumber.T, ok, "error returned")
		assert.NoError(gucumber.T, err)
	})

	gucumber.And(`^I have a list of services$`, func() {
		mapCreateClients()
	})

	gucumber.And(`^I take a snapshot of my resources$`, func() {
		// Can't take a memory snapshot here, because gucumber does some
		// allocation between each instruction leading to unreliable numbers
	})

	gucumber.When(`^I create a client for each service$`, func() {
		buildAnArrayOfClients()
	})

	gucumber.And("^I execute (\\d+) command\\(s\\) on each client$", func(i1 int) {
		clientFns := gucumber.World["clientFns"].([]func())
		err := benchmarkTask(fmt.Sprintf("%d_commands_on_clients", i1), clientFns, i1)
		gucumber.World["error"] = err
	})

	gucumber.And(`^I destroy all the clients$`, func() {
		delete(gucumber.World, "clientFns")
		runtime.GC()
	})

	gucumber.Given(`^I have a (\d+) byte file$`, func(i1 int) {
		gucumber.World["file"] = make([]byte, i1)
	})

	gucumber.When(`^I upload the file$`, func() {
		svc := s3.New(mock.Session)
		memStatStart := &runtime.MemStats{}
		runtime.ReadMemStats(memStatStart)
		gucumber.World["start"] = memStatStart

		svc.PutObjectRequest(&s3.PutObjectInput{
			Bucket: aws.String("bucketmesilly"),
			Key:    aws.String("testKey"),
			Body:   bytes.NewReader(gucumber.World["file"].([]byte)),
		})
	})

	gucumber.And(`then download the file$`, func() {
		svc := s3.New(mock.Session)
		svc.GetObjectRequest(&s3.GetObjectInput{
			Bucket: aws.String("bucketmesilly"),
			Key:    aws.String("testKey"),
		})
		memStatEnd := &runtime.MemStats{}
		runtime.ReadMemStats(memStatEnd)
		memStatStart := gucumber.World["start"].(*runtime.MemStats)
		if memStatStart.Alloc < memStatEnd.Alloc {
			gucumber.World["error"] = errors.New("Leaked memory")
		}
	})
}