Skip to content

Commit

Permalink
Merge pull request #54 from bokyoung89/feature/#51-test
Browse files Browse the repository at this point in the history
test #51- 자동화 테스트 시나리오 작성
bokyoung89 authored Mar 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents b81d3ce + b5b9c80 commit 76b5dec
Showing 5 changed files with 68 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -37,4 +37,6 @@ out/
.vscode/

###
.env
.env
/ngrinder
/user-service/src/main/resources/data.sql
13 changes: 13 additions & 0 deletions http-Reqeust-Test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Dockerfile

FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./http_request_tool.py" ]
48 changes: 48 additions & 0 deletions http-Reqeust-Test/http_request_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import requests
import random
from concurrent.futures import ThreadPoolExecutor

def send_http_request(url, request_body=None, headers=None):
try:
response = requests.post(url, json=request_body, headers=headers)
if response.status_code == 200:
print(f"주문 생성 성공, 주문 정보 : {response.json()}")
else:
print(f"재고 없음, 주문 정보 : {response.json()}")
except Exception as e:
print(f"Error sending request to {url}: {e}")

def main():
# Set the number of concurrent requests (N)
num_requests = 50

# Set the target URL
target_url = "http://172.29.224.1:8085/api/v1/orders"

# Create a ThreadPoolExecutor to send concurrent requests
with ThreadPoolExecutor(max_workers=num_requests) as executor:
# Use a list comprehension to create a list of tasks
tasks = []
for _ in range(num_requests):
# Generate random user_id
user_id = random.randint(1, 100)
# Define request body and headers
request_body = {
"productId" : 13,
"quantity" : 1,
"address" : "서울시"
}
headers = {
"principalId": str(user_id),
"Content-Type": "application/json"
}
# Submit task to ThreadPoolExecutor
task = executor.submit(send_http_request, target_url, request_body, headers)
tasks.append(task)

# Wait for all tasks to complete
for future in tasks:
future.result()

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions http-Reqeust-Test/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@@ -21,10 +22,10 @@ public class OrderController {
* 결제 진입 : 구매하기 클릭 시 주문 생성
*/
@PostMapping
public Response<OrderResponse> create(@RequestBody OrderCreateRequest request,
public Long create(@RequestBody OrderCreateRequest request,
@RequestHeader(name = "principalId") Long principalId) {
Order order = orderService.create(request.getProductId(), request.getQuantity(), request.getAddress(), principalId);
return Response.success(OrderResponse.fromOrder(order));
return order.getId();
}

/**

0 comments on commit 76b5dec

Please sign in to comment.