Skip to content

Commit

Permalink
add naive teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
tng-daniel-haehnke committed Aug 10, 2023
1 parent 47682fc commit 1ef040a
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
22 changes: 22 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ func Prepare() error {
return nil
}

// Remove user data
func UnPrepare() error {
mg.Deps(EnsureK6, mkOutputDir)

env := addHarborSizeToEnv(addHarborEnv(nil))

scripts, err := filepath.Glob("./scripts/data/teardown/*.js")
if err != nil {
return err
}

for _, script := range scripts {
args := getK6RunArgs(script)

if err := sh.RunWithV(env, K6Command, args...); err != nil {
return err
}
}

return nil
}

// Execute a specific test
func Run(test string) error {
mg.Deps(EnsureK6, mkOutputDir)
Expand Down
41 changes: 41 additions & 0 deletions scripts/data/teardown/01-project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// prepare projects
import { Rate } from 'k6/metrics'
import counter from 'k6/x/counter'
import { Harbor } from 'k6/x/harbor'

import { Settings } from '../config.js'
import { numberToPadString } from '../helpers.js'

const settings = Settings()

const totalIterations = settings.ProjectsCount

export let successRate = new Rate('success')

export let options = {
setupTimeout: '6h',
duration: '24h',
vus: Math.min(settings.VUS, totalIterations),
iterations: totalIterations,
thresholds: {
'success': ['rate>=1'],
'iteration_duration{scenario:default}': [
`max>=0`,
],
'iteration_duration{group:::setup}': [`max>=0`],
}
};

const harbor = new Harbor(settings.Harbor);

export default function () {
const suffix = numberToPadString(counter.up(), settings.ProjectsCount)

try {
harbor.deleteProject({ projectName: `${settings.ProjectPrefix}-${suffix}` })
successRate.add(true)
} catch (e) {
successRate.add(false)
console.error(e.message)
}
}
41 changes: 41 additions & 0 deletions scripts/data/teardown/02-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// prepare users
import { Rate } from 'k6/metrics'
import counter from 'k6/x/counter'
import { Harbor } from 'k6/x/harbor'

import { Settings } from '../config.js'
import { numberToPadString } from '../helpers.js'

const settings = Settings()

const totalIterations = settings.UsersCount

export let successRate = new Rate('success')

export let options = {
setupTimeout: '6h',
duration: '24h',
vus: Math.min(settings.VUS, totalIterations),
iterations: totalIterations,
thresholds: {
'success': ['rate>=1'],
'iteration_duration{scenario:default}': [
`max>=0`,
],
'iteration_duration{group:::setup}': [`max>=0`],
}
};

const harbor = new Harbor(settings.Harbor)

export default function () {
const suffix = numberToPadString(counter.up(), settings.UsersCount)

try {
harbor.deleteUser(`${settings.UserPrefix}-${suffix}`)
successRate.add(true)
} catch (e) {
successRate.add(false)
console.error(e.message)
}
}

0 comments on commit 1ef040a

Please sign in to comment.