Skip to content

Commit

Permalink
Merge pull request #21 from boostcampwm-2024/test-#20-load-test-script
Browse files Browse the repository at this point in the history
✅ test: nGrinder 메인페이지 API 부하테스트 스크립트 추가
  • Loading branch information
KWAKMANBO authored Jan 16, 2025
2 parents bce054f + 74ab132 commit 4a15403
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
15 changes: 15 additions & 0 deletions nGrinder/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
controller:
image: ngrinder/controller
restart: always
ports:
- "9000:80"
- "16001:16001"
- "12000-12009:12000-12009"
volumes:
- ~/ngrinder-controller:/opt/ngrinder-controller
agent:
image: ngrinder/agent
restart: always
links:
- controller
112 changes: 112 additions & 0 deletions nGrinder/script/main_page_load_test.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.ngrinder.http.HTTPRequest
import org.ngrinder.http.HTTPRequestControl
import org.ngrinder.http.HTTPResponse
import org.ngrinder.http.cookie.Cookie
import org.ngrinder.http.cookie.CookieManager

@RunWith(GrinderRunner)
class TestRunner {

public static GTest test
public static HTTPRequest request
public static Map<String, String> headers = [:]
public static Map<String, Object> params = [:]
public static List<Cookie> cookies = []

@BeforeProcess
public static void beforeProcess() {
HTTPRequestControl.setConnectionTimeout(300000)
test = new GTest(1, "juchumjuchum.site")
request = new HTTPRequest()
grinder.logger.info("before process.")
}

@BeforeThread
public void beforeThread() {
test.record(this, "testThemeChange")
test.record(this, "testStockFluctuation")
test.record(this, "testTopViews")
test.record(this, "testIndex")
test.record(this, "testStatus")
grinder.statistics.delayReports = true
grinder.logger.info("before thread.")
}

@Before
public void before() {
request.setHeaders(headers)
CookieManager.addCookies(cookies)
grinder.logger.info("before. init headers and cookies")
}

@Test
public void testThemeChange() {
HTTPResponse response = request.GET("http://juchumjuchum.site/api/user/theme")
if (response.statusCode == 301 || response.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
} else {
assertThat(response.statusCode, is(200))
if (response.statusCode != 200) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
}
}
}


@Test
public void testStockFluctuation() {
Map<String, Object> params = ["limit": "10", "type": "increase"]
HTTPResponse response = request.GET("http://juchumjuchum.site/api/stock/fluctuation", params)
if (response.statusCode == 301 || response.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
} else {
grinder.logger.info("Response Status Code: ${response.statusCode}")
assertThat(response.statusCode, is(200))
}
}

@Test
public void testTopViews() {
Map<String, Object> params = ["limit": "5"]
HTTPResponse response = request.GET("http://juchumjuchum.site/api/stock/topViews", params)
if (response.statusCode == 301 || response.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
} else {
grinder.logger.info("Response Status Code: ${response.statusCode}")
assertThat(response.statusCode, is(200))
}
}

@Test
public void testIndex() {
HTTPResponse response = request.GET("http://juchumjuchum.site/api/stock/index")
if (response.statusCode == 301 || response.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
} else {
grinder.logger.info("Response Status Code: ${response.statusCode}")
assertThat(response.statusCode, is(200))
}
}

@Test
public void testStatus() {
HTTPResponse response = request.GET("http://juchumjuchum.site/api/auth/status")
if (response.statusCode == 301 || response.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", response.statusCode)
} else {
grinder.logger.info("Response Status Code: ${response.statusCode}")
assertThat(response.statusCode, is(200))
}
}
}

0 comments on commit 4a15403

Please sign in to comment.