Skip to content

Commit

Permalink
feat: add PDF API URL and enhance load testing scenarios with proposa…
Browse files Browse the repository at this point in the history
…l interactions
  • Loading branch information
kneerose committed Jan 20, 2025
1 parent 2663fc0 commit 11b4fb1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
3 changes: 3 additions & 0 deletions tests/load-testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Before you start, ensure you have the following prerequisites installed:

```bash
export API_URL=https://govtool.cardanoapi.io/api
export PDF_API_URL=https://z74f91f2d-zb0719f09-gtw.z937eb260.rustrocks.fr/api
export PEAK_USERS=100
export RAMP_DURATION=40 # in seconds
export STRESS_DURATION=40 # in seconds
Expand All @@ -33,13 +34,15 @@ docker run \
-e PEAK_USERS=100 \
-e STRESS_DURATION=40 \
-e API_URL='https://govtool.cardanoapi.io/api'\
-e PDF_API_URL='https://z74f91f2d-zb0719f09-gtw.z937eb260.rustrocks.fr/api'\
govtool/load-testing
```

## Environment Variables
Explain the environment variables used in the project and their purpose.

- API_URL: The URL of the API being tested.
- PDF_API_URL: The URL of the PDF API being tested.
- PEAK_USERS: The number of users to be injected during the test for each scenario.
- RAMP_DURATION:The duration over which the user rate gradually increases.
- STRESS_DURATION: The duration over which the stress peak occurs.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static io.gatling.javaapi.core.CoreDsl.*;

public class AuthenticationAction {
public static ChainBuilder connect (List<String> knownDrepIds) {
public static ChainBuilder connect (List<String> knownDrepIds,List<String> knownProposaList) {

var drepStream = Stream.generate((Supplier<Map<String, Object>>) () -> {
var randomIndex=ThreadLocalRandom.current().nextInt(0,knownDrepIds.size());
Expand All @@ -23,9 +23,17 @@ public static ChainBuilder connect (List<String> knownDrepIds) {
}
).iterator();

var proposalListStream = Stream.generate((Supplier<Map<String, Object>>) () -> {
var randomIndex=ThreadLocalRandom.current().nextInt(0,knownProposaList.size());
var proposalDiscussionId = knownProposaList.get(randomIndex);
return Collections.singletonMap("proposalDiscussionId", proposalDiscussionId);
}
).iterator();

return group("Login")
.on(feed(RandomDataFeeder.stakeKey)
.feed(drepStream)
.feed(proposalListStream)
.exec(ApiService.getCurrentDelegation)
.exec(ApiService.getParams)
.exec(ApiService.getDRepVotingPower)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import io.gatling.javaapi.core.PopulationBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import org.cardano.govtool.ApiService;
import org.cardano.govtool.actions.Action;
import org.cardano.govtool.actions.AdaHolderAction;
import org.cardano.govtool.actions.AuthenticationAction;
import org.cardano.govtool.actions.DRepAction;
import org.cardano.govtool.actions.ProposalAction;
import org.cardano.govtool.feeders.DrepListFetcher;
import org.cardano.govtool.feeders.PageVisits;
import org.cardano.govtool.feeders.ProposalListFetcher;

import java.util.List;
import java.util.Optional;
Expand All @@ -20,26 +24,30 @@

public class VvaSimulation extends Simulation {
private static final String API_URL = Optional.ofNullable(System.getenv("API_URL")).orElse("https://govtool.cardanoapi.io/api2");
private static final String PDF_API_URL = Optional.ofNullable(System.getenv("PDF_API_URL")).orElse("https://z74f91f2d-zb0719f09-gtw.z937eb260.rustrocks.fr/api");
private static final int PEAK_USERS = Integer.parseInt(Optional.ofNullable(System.getenv("PEAK_USERS")).orElse("600"));
private static final int STRESS_DURATION = Integer.parseInt(Optional.ofNullable(System.getenv("STRESS_DURATION")).orElse("20"));
private static final int RAMP_DURATION = Integer.parseInt(Optional.ofNullable(System.getenv("RAMP_DURATION")).orElse("20"));
private List<String>knownDreps;
private List<String> knownProposaList;

@Override
public void before() {
System.out.printf("Base API URL: %s%n", API_URL);
System.out.printf("PDF API URL: %s%n", PDF_API_URL);
System.out.printf("Peak users count: %d%n", PEAK_USERS);
System.out.printf("Ramping users over %d seconds%n", RAMP_DURATION);
System.out.printf("Stress interval %d seconds%n", STRESS_DURATION);

}

private PopulationBuilder makeScenario(String name, ChainBuilder chain, double userPercent) {
private PopulationBuilder makeScenario(String name, ChainBuilder chain, double userPercent,HttpProtocolBuilder protocol) {
var rampUserRate = ((double) PEAK_USERS) * userPercent / (double) RAMP_DURATION;
return scenario(name).exec(AuthenticationAction.connect(knownDreps).pause(2).exec(chain)).injectOpen(
return scenario(name).exec(AuthenticationAction.connect(knownDreps,knownProposaList).pause(2).exec(chain)).injectOpen(
nothingFor(5),
constantUsersPerSec(rampUserRate).during(RAMP_DURATION),
stressPeakUsers(PEAK_USERS).during(STRESS_DURATION)
);
).protocols(protocol);
}

private final HttpProtocolBuilder httpProtocol = http
Expand All @@ -50,28 +58,50 @@ private PopulationBuilder makeScenario(String name, ChainBuilder chain, double u
.acceptLanguageHeader("en-US,en;q=0.9")
.userAgentHeader("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");

private final HttpProtocolBuilder pdfHttpProtocol = http
.baseUrl(PDF_API_URL)
.inferHtmlResources(AllowList(), DenyList(".*\\.js", ".*\\.css", ".*\\.gif", ".*\\.jpeg", ".*\\.jpg", ".*\\.ico", ".*\\.woff", ".*\\.woff2", ".*\\.(t|o)tf", ".*\\.png", ".*\\.svg", ".*detectportal\\.firefox\\.com.*"))
.acceptHeader("application/json;charset=utf-8")
.header("authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjgyNywiaWF0IjoxNzM3MzkxNzcyLCJleHAiOjE3Mzk5ODM3NzJ9.UUghEOdUy0w4AdiEjvHmDWGUUiqOxI221PLL70kvC5g")
.acceptEncodingHeader("gzip, deflate, br")
.acceptLanguageHeader("en-US,en;q=0.9")
.userAgentHeader("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");

// Load Simulation
{
knownDreps= DrepListFetcher.fetchDrepIds(API_URL);
var DREP_USER_RATI0=0.3
knownProposaList = ProposalListFetcher.fetchProposalIds(PDF_API_URL);

var DREP_USER_RATI0=0.3;
setUp(
makeScenario("User Connects and Leave", exec(), 0.1)
makeScenario("User Connects and Leave", exec(), 0.1,httpProtocol)
, makeScenario("User Registers as Drep",
exec(DRepAction.registerAsDRep), 0.1),
exec(DRepAction.registerAsDRep), 0.1,httpProtocol),
makeScenario("User Views Proposals",
exec(Action.viewProposals), 0.2)
exec(Action.viewProposals), 0.2,httpProtocol)
, makeScenario("AdaHolder delegates to Drep",
exec(AdaHolderAction.delegateToDRep), 0.1)
, makeScenario("ListProposals", PageVisits.visitProposalPage(), 0.2)
exec(AdaHolderAction.delegateToDRep), 0.1,httpProtocol)
, makeScenario("ListProposals", PageVisits.visitProposalPage(), 0.2,httpProtocol)

// Further split drep users on scenarios
, makeScenario("Drep view Votes",
exec(Action.viewProposals).pause(2).exec(Action.viewProposals), DREP_USER_RATI0 * 0.5)
exec(Action.viewProposals).pause(2).exec(Action.viewProposals), DREP_USER_RATI0 * 0.5,httpProtocol)
, makeScenario("Drep votes on Proposal",
exec(DRepAction.vote), DREP_USER_RATI0 * 0.4)
exec(DRepAction.vote), DREP_USER_RATI0 * 0.4,httpProtocol)
, makeScenario("Drep Retirement",
exec(DRepAction.retireAsDRep), DREP_USER_RATI0 * 0.1)
exec(DRepAction.retireAsDRep), DREP_USER_RATI0 * 0.1,httpProtocol)

, makeScenario("ListProposalDiscussions", PageVisits.visitProposalDiscussionPage(), 0.2,pdfHttpProtocol)
, makeScenario("Comment on proposal", exec(ProposalAction.commentOnProposal), 0.5,pdfHttpProtocol)
, makeScenario("Proposal comments", exec(ApiService.getComments), 0.5,pdfHttpProtocol)
, makeScenario("Proposal Active polls", exec(ApiService.getActivePolls), 0.2,pdfHttpProtocol)
, makeScenario("proposal Inactive polls", exec(ApiService.getInActivePolls), 0.2,pdfHttpProtocol)
, makeScenario("proposal types", exec(ApiService.getGovernanceActionType), 0.2,pdfHttpProtocol)
, makeScenario("Like/Dislike proposal", exec(ProposalAction.voteOnProposal), 0.5,pdfHttpProtocol)
, makeScenario("Create proposal draft", exec(ProposalAction.createProposalDraft), 0.5,pdfHttpProtocol)
, makeScenario("Create info proposal", exec(ProposalAction.createInfoProposal), 0.5,pdfHttpProtocol)
).protocols(httpProtocol);
}


}

0 comments on commit 11b4fb1

Please sign in to comment.