This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'k6/http' | |
import { sleep, check } from 'k6' | |
import { Rate, Trend } from 'k6/metrics' | |
// Custom defined metrics | |
const lowerThan2sRate = new Rate('lower_than_2s') | |
const durationInSeconds = new Trend('duration_in_seconds') | |
// This BASE_URL won't work if you're using Docker. | |
// You'll need to know the IP address of the host. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function teardown(data) { | |
const params = { | |
headers: { | |
Authorization: `Bearer ${data.token}` | |
} | |
} | |
// To clear/truncate the injected table we need token | |
http.get(`${BASE_URL}/users/clear`, params) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function setup() { | |
const authParams = { | |
headers: { 'Content-Type': 'application/json' }, | |
} | |
const authPayload = { | |
email: '[email protected]', | |
password: 'user1', | |
fullname: 'user1' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. init code | |
export function setup() { | |
// 2. setup code | |
} | |
export default function (data) { | |
// 3. VU code | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from 'k6/http' | |
import { sleep } from 'k6' | |
// This BASE_URL won't work if you're using Docker. | |
// You'll need to know the IP address of the host. | |
// Then replace localhost with the IP address. | |
const BASE_URL = 'http://localhost:3000' | |
export default function() { | |
const res = http.get(BASE_URL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"net/http" | |
"strconv" | |
"time" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"net/http/httptest" | |
"strconv" | |
"testing" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"net/http" | |
"strconv" | |
"time" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"net/http" | |
"strconv" | |
"time" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "testing" | |
func BenchmarkCalculate(b *testing.B) { | |
for n := 0; n < b.N; n++ { | |
Calculate(1, 2) | |
} | |
} |