forked from boostcampwm-2024/web17-juchumjuchum
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from boostcampwm-2024/test-#20-load-test-script
✅ test: nGrinder 메인페이지 API 부하테스트 스크립트 추가
- Loading branch information
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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)) | ||
} | ||
} | ||
} |