Skip to content

Instantly share code, notes, and snippets.

View agusrichard's full-sized avatar

Agus Richard Lubis agusrichard

View GitHub Profile
@agusrichard
agusrichard / main.go
Last active September 18, 2021 17:21
package main
import (
"fmt"
"math/rand"
"time"
)
func Calculate(x, y int64) int64 {
// get random integer between 0 and 100
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/http/httptest"
"testing"
)
package main
import (
"encoding/json"
"net/http"
"strconv"
)
type Response struct {
Message string `json:"message"`
package main
import (
"log"
"testing"
)
// You can use testing.T, if you want to test the code without benchmarking
func setupSuite(tb testing.TB) func(tb testing.TB) {
log.Println("setup suite")
package main
import "testing"
func TestDoubleMe(t *testing.T) {
table := []struct {
input float64
expected float64
}{
{1, 2},
package main
import (
"fmt"
)
func doubleMe(x float64) float64 {
return x * 2
}
version: '3'
services:
master:
image: locustio/locust
ports:
- "8089:8089"
volumes:
- ./:/mnt/locust
command: -f /mnt/locust/main.py --master -H http://master:8089
import time
import random
import gevent
from locust import HttpUser, task, between, TaskSet, events
from locust.runners import STATE_STOPPING, STATE_STOPPED, STATE_CLEANUP, WorkerRunner
def fast_task(user):
user.client.get('/fast', headers={'login-token': user.login_token})
import time
import uvicorn
from typing import List
from pydantic import BaseModel
from fastapi import FastAPI, Header, HTTPException, Depends
app = FastAPI()
@app.get('/hello')
from locust import HttpUser, task, between
class HelloWorldUser(HttpUser):
wait_time = between(0.5, 2.5)
@task
def hello_world(self):
self.client.get('/hello')