The LB-Tester is a testser made especially to test the performance and the trustiness of the load balancer that will be made for the project Latest Collection. An example of usage is available on src/index.ts
Table of Contents:
The configurations are saved in testconfig.json file. By changing the configurations, they will be changed in this file and saved to be always used while the tests running. So be sure that you always set the correct configurations for your tests.
import configurator from './configurations/configurator';
configurator.setRequestMethod('Get'); //Default 'Get'.
configurator.setBaseUrl('http://localhost:3000/data/#{tenantId}/inbox'); //Default 'http://localhost:3000'.
#{tenantId} will be replaced with the given tenantId during the tests.
configurator.setExpectationsUsingAddressBook(true) //Default false.
configurator.setExpectedResponseCode(200) //Default 200.
configurator.setAddressBookUrl('http://localhost:3100/loadbalancer/addressbook') //Default 'http://localhost:3100/loadbalancer/addressbook'.
configurator.setRandomizeTestLists(true) //Default false.
configurator.setLBAuthenticationToken('MasterTestToken') //Default 'MasterTestToken'.
configurator.setResponseTimeHeader('X-Response-Time'); //Default "".
- configurator.setParallelTest(true) //Default 'false'
- configurator.setParallelTestConcurrency(5) //Default 1
- configurator.setCheckRAMUsage(true); //Set true to enable or false to disable default (false). When disable no need for the rest configurating steps.
- configurator.setRAMCheckRequestMethod('Post'); //Request method to get the RAM details.
- configurator.setRAMCheckRequestUrl('https://localhost:3100/loadbalancer/data'); //Request url to get the RAM details. Default 'https://localhost:3100/loadbalancer/data'.
- configurator.setRAMCheckRequestBody({ "command": "inspect" }); //Request body to get the RAM details. Default {}. In case of using RAM inspection using the load balancer set it as empty object like this configurator.setRAMCheckRequestBody({});
- configurator.setRAMCheckRequestHeaders({'Accept-Encoding': 'gzip'}); //This will add these headers to the RAM requests.
- configurator.setMultiRAMCheck(true); //Set true if the RAM usage will be inspected from multi servers/services using the load balancer.
- configurator.setMultiTimeUsageCheck(true); //Set true if the time usage will be inspected from multi servers/services using the load balancer.
- configurator.setTestFinishSoundAlert(true); //Play alert sound when tests has been finished
You have first to prepare the request parameters and the test objects to add them to tester.
- import testObjectFunctions from './functions/testObjectFunctions';
- import testObjectListFunctions from './functions/testObjectListFunctions';
RequestParameter(name, value)
const requestParamaters = [ { name: 'token', value: 'MasterToken' } ];
createNewTestObject(testName, tenantId, requestParameters?, requestBody?, requestHeaders?, additionUrl?)
const testObject = testObjectFunctions.createNewTestObject('test1', '00000', requestParamaters);
createNewTestObjectList(originalTestObject, startTenantId, totalTestObjects, fixedTenant, incrementStep)
let testObjectList = testObjectListFunctions.createNewTestObjectList(testObject, '00000', 1000, false, 1);
To be able to run the tests you have first to add the testobjects to the tester object as follow:
import tester from './tester/tester';
tester.addTestObject(testObject); //Add the given object to the current list.
or
tester.setTestObjectList(testObjectList); //Replaces the current list with the given list.
or
tester.addTestObjectList(testObjectList2); //Add the given list to the current list.
tester.addWarmUpTestObject(testObject, 100); //testObject is a TestObject to warm up with, 100 is the total of warm up rounds.
To run the tests call the function startTest() from tester object as follow:
tester.startTest();
After running the test process, the tester will automatically log the results to the console. But if you want later to see the results, you can see the latest test result using one of these ways:
The path of testlog.txt is: /testlog.txt
- import logger from '../logger/logger';
- logger.log();
- The path of testresults.json is: /testresults.json
- The path of teststimeusagechart.png is: /teststimeusagechart.png
- The path of testsramusagechart.png is: /testsramusagechart.png
This module is used to manage the TestObject.
- createNewTestObject(testName:string, tenantId: string, requestParameters?: RequestParameter[], requestBody?: any, requestHeaders?: object): TestObject //This function creates a new TestObject.
- createNewTestObjectWithExpectations(testName:string, expectedServerName: string, expectedServerPort: string, tenantId: string, requestParameters?: RequestParameter[], requestBody?: any, requestHeaders?: object, urlAddition?: string): TestObject //This function creates a new TestObject based on the info that has been given inclusive the expected server name and port.
- getRequestParametersAsString(testObject: TestObject): string //Get the request paramaters list from TestObject as string like this 'name1=val1&name2=val2'.
- toTesterOptions(testObject: TestObject): TesterOptions //Get a TesterOptions object from a TestObject using the attributes of the given TesterObject and the configurations.
This is used to manage the TestObjectList.
- createNewTestObjectList(originalTestObject: TestObject, startTenantId: string, totalTestObjects: number, fixedTenant: boolean, incrementStep: number): TestObjectList //This function creates a new TestObjectList.
- addTestObjectToList(testObjectList: TestObjectList, testObject: TestObject): void //Adds the given test object into the given test objects list.
- incrementTenantId(startTenantId: string, incrementValue: number): string //Increments the startTenantId and return it as string.
- generateTestObjects(originalTestObject: TestObject, startTenantId: string, totalTestObjects: number, fixedTenant: boolean, incrementStep: number): TestObject[] //Generate the TestObjects and add them to the test objects list.
JSON file to save the test configurations that will be used for all the tests during testing
- "requestMethod": string //The method of all requests (Default GET)
- "baseurl": string //The base url that will be used in all requests (Default http://localhost:3000)
- "expectedResponseCode": number //The expected response code of all requests (Default 200)
- "expectationsUsingAddressBook": boolean //To set the expected server name and port automatically using the address book.
- "addressBookUrl": string //The request url of the addressbook from the loadbalancer (Default http://localhost:3100/loadbalancer/addressbook)
- "randomizeTestLists": boolean //If the tester has to RANDOM resort the testobject list.
- "lbAuthenticationToken": string //Authentication token when using the load balancer (default "MasterTestToken")
- "checkRAMUsage": boolean //If the tester has to check the RAM while testing or not (Default false)
- "ramCheckRequestMethod": string //Request method to get RAM details (Default Post)
- "ramCheckRequestUrl": string //Request url to get RAM details (default "https://localhost:3100/loadbalancer/data")
- "ramCheckRequestBody": {} //Request body to get RAM details (default {})
- "ramCheckRequestHeaders": {} //Request headers to get RAM details (default {})
- "multiRAMCheck": boolean //If the tester needs to check the RAM usage of multi servers (default false)
- "multiTimeUsageCheck": false //If the tester needs to check the time usage of multi servers (default false)
- "parallelTest": boolean //If the tester has to run tests in parallel (default false)
- "parallelTestConcurrency": number //The concurrency total when run parallel test (default 1)
- "testFinishSoundAlert": boolean //Play sound alert when the test has been finished (default false)
- "responseTimeHeader": string //The response time usage that will be in the response (default "")
A helper module to be able to read and update the attributes of testconfig.json file
- setRequestMethod(requestMethod: string): void
- setBaseUrl(baseUrl: string): void
- setExpectedResponseCode(responseCode: number): void
- setExpectationsUsingAddressBook(expectationsUsingAddressBook: boolean): void
- setAddressBookUrl(addressBookUrl: string): void
- setRandomizeTestLists(randomizeTestLists: boolean): void
- setLBAuthenticationToken(authenticationToken: string): void
- setCheckRAMUsage(checkRAMUsage: boolean): void
- setRAMCheckRequestMethod(ramCheckRequestMethod: string): void
- setRAMCheckRequestUrl(ramCheckRequestUrl: string): void
- setRAMCheckRequestBody(ramCheckRequestBody: object): void
- setRAMCheckRequestHeaders(ramCheckRequestHeaders: object): void
- setMultiRAMCheck(multiRAMCheck: boolean): void
- setMultiTimeUsageCheck(multiTimeUsageCheck: boolean): void
- setParallelTest(asynchTest: boolean): void
- setParallelTestConcurrency(parallelTestConcurrency: number): void
- setTestFinishSoundAlert(testFinishSoundAlert: boolean): void
- setResponseTimeHeader(responseTimeHeader: string): void
- getRequestMethod(): string
- getBaseUrl(): string
- getExpectedResponseCode(): number
- isExpectationsUsingAddressBook(): boolean
- getAddressBookUrl(): string
- isRandomizeTestLists(): boolean
- getLBAuthenticationToken(): string
- isCheckRAMUsage(): boolean
- getRAMCheckRequestMethod(): string
- getRAMCheckRequestUrl(): string
- getRAMCheckRequestBody(): object
- getRAMCheckRequestHeaders(): AxiosRequestHeaders
- isMultiRAMCheck(): boolean
- isMultiTimeUsageCheck(): boolean
- isParallelTest(): boolean
- getParallelTestConcurrency(): number
- isTestFinishSoundAlert(): boolean
- getResponseTimeHeader(): string
- resetToDefault(): void
This module manages the logging into the log file testlog.txt
- increaseSucceedOrBrokenRequests(succeed: boolean): void //Increase succeed and broken tests in list to give a better report at the end.
- secceedAndBrokenListToString(): string //Turn increased succeed and broken results into string.
- addPassedTest(timeUsage: number, server: string): void //Increases the passed tests and the time usage during testing current test object.
- addFailedTest(fault: string, timeUsage: number): void //Increases the failed tests and the time usage during testing current test object. It also adds the fail description to the fails descriptions list to add it later to the log.
- addError(error: string, timeUsage: number): void //Increases the errors. It also adds the error description to the errors descriptions list to add it later to the log.
- addRAMUsage(ramUsage: number, server: string): void //Add ramUsage to be plotted at the end of logging.
- addWarmpUpRAMUsage(ramUsage: number): void //Add warmUpRAMUsage to be plotted at the end of logging.
- addRAMUsageAndCapacity(testRAMUsage: TestRAMUsage): void //Add ramUsage and RAM capacity to be plotted at the end of logging.
- setWarmUpProcessDuration(duration: number): void //Set the total warming up process duration
- setTestProcessDuration(duration: number): void //Set the total testing process duration
- serverIsBroken(): void //Calculate how many requests can the server manage at the same time until it breaks and how much time does that cost.
- prepair(): void //Calculates the logger's informations and writes them to testlog.txt file.
- plotTestResults(width: number): Promise<void> //Plot the tests usage times and save it to teststimeusagechart.png file.
- plotTestRAMUsage(width: number): Promise<void> //Plot the RAM usage during the tests and save it to testsramusagechart.png file.
- plotMultiTestRAMUsage(): Promise<void> //This function loops through the RAM expected servers and runs the plot for each one of them.
- plotOneMultiTestRAMUsage(serverName:string, listToPlot: number[], width: number): Promise<void> //Plot the RAM usage of one server during the tests and save it to testsramusagechartof[hostport].png file.
- plotWarmpUpRAMUsage(width: number): Promise<void> //Plot the RAM usage during the warming up and save it to warmpupramusagechart.png file.
- writeJsonTestResults(testResultObjects: TestResultObject[]): void //This function writes the test result objects to testresults.json file.
- readTestLog(): string //Reads the testlog.txt file and returns its contents as string.
- log(): void //Logs the contents of the testlog.txt file on the console.
- reset(): void //Reset all counters and lists inside the logger object to start a new test.
- clear(): void //Clear testlog.txt and testresults.json files contents.
Here will be the requests responses results compared with the expected results of the tests. Then the results of the check will be later added to the testlog.txt file using logger module.
- convertTestCheckObjectToResultObject(testCheckObject: TestCheckObject, testNumber: number): TestResultObject //Extracts the useful informations from the TestCheckObject to make a TestResultObject wich will be written in testresults.json file.
- check(testChechList: TestCheckObject[]): Promise<void> //Compares the requests results with the expected results and adds the check results to testlog.txt file.
Inside the tester will be the requests called and the responses of them sent to be checked by testchecker module
- callApi(options: TesterOptions): Promise<TestCallResponse> //Calls a request and returns the response of it.
- callRAMUsageApi(body: object): Promise<TestRAMUsage> //This function calls the RAM usage api on itself.
- getRAMBody(body: object): object //This function decides whether the RAM usage will use the body in configurations or the body has been sent with the tenantId from the tests.
- getAddressBook(): Promise<AddressBook | any> //This function calls the api of the addressbook in the loadbalancer.
- setTestObjectsAddresses(): Promise<boolean> //Assign the expected server name and port for all TestObjects including the warmUpTestObject.
- randomSortTestObjectsList(testObjects: TestObject[]): Promise<void> //This function resorts the testObjects list randomly.
- setTestObjectList(testObjectList: TestObjectList): void //Replace the current list of TestObject with the given one to be tested.
- addTestObject(testObject: TestObject): void //Add a TestObject to the TestObjects list.
- addTestObjectList(testObjectList: TestObjectList): void //Add the given TestObjectList to the current list.
- getTestObjectList(): TestObjectList[] //Returns the current TestObjectList.
- addWarmUpTestObject(testObject: TestObject, rounds: number): void //Add TestObject and rounds total per object to the warm up list.
- beep(): Promise<void> //Play beep sound.
- doWarmUp(multibar: MultiBar): Promise<void> //This function runs the warming up.
- doSequentialTests(testCheckList: TestCheckObject[], multibar: MultiBar): Promise<void> //This function runs the tests sequentially.
- doOneParallelTest(testObject: TestObject, testCheckList: TestCheckObject[]): Promise<void> //This function runs one test. It's used for parallel only tests.
- doBatchParallelTests(testObjectsBatch: TestObject[], testCheckList: TestCheckObject[], multibar: MultiBar): Promise<void> //This function runs a batch of parallel tests. It plays the rule of a user.
- splitListIntoBatches(testObjects: TestObject[], batchCount: number): TestObject[][] //This function splits the testObjectsList into batches depending on concurrency number.
- doParallelTests(testCheckList: TestCheckObject[], multibar: MultiBar): Promise<void> //This function runs the tests parallel.
- startTest(): Promise<void> //This function runs the warmup and tests functions.
Within the LBTester are there several types made to make it easier to understand and to use. These types are as following:
Object that contains the request options.
- url: string //The base url + the requests parameters as one url.
- data?: any //(optional) Data object.
- headers?: AxiosRequestConfig<any> //(optional) The request headers.
Object to contain if the request succeed or failed, the response and the usage time during the requesting.
- succeed: boolean //The result of the api call, if the call succeed or failed with error.
- response?: { status: number; headers: object } //The needed info from the response of the api call.
- error?: any //The error description if the api call failed with error.
- testRAMUsage?: number //The ram usage during this test.
This object contains the total used RAM and the RAM capacity in the server during a test.
- totalRAM: number //Total RAM capacity in the server.
- usedRAM: number //Total used RAM in the server.
This object contains testobject, testeroptions and testcallresponse that are useful while checking the tests reponse and comparing the results.
- testObject: TestObject
- testerOptions: TesterOptions
- testCallResponse: TestCallResponse
This objects contains the useful details for the user to be written in testresults.json file.
- testNumber: number
- testObject: TestObject
- testerOptions: TesterOptions
- testCallResponse: { status: number, headers: object, testRAMUsage?: number }
This object contains how many requests has been succeed or refused by the server because of too many requests
- succeed: boolean //If server accepted or breaks the request.
- total: number //Total accepted before next break, or total breaks before next acception.
This object plays the rule of the addressbook in the loadbalancer.
- [tenantId: string]: TenantAddress //The TenantAddress object assigned to the tenantId as a key.
RequestParameter is a class wich plays the role of a request parameter:
- name: string; //The request parameter name.
- value: any; //The request parameter value.
TenantAddress is used to be easier to use the contents of the returned addressbook from the loadbalancer:
- tenantId: string; //The tenant id.
- serverProtocol: string; The protocol of the server.
- serverName: string; //The name of the server.
- serverPort: number; //The port of the server.
TestObject is used to add test options for each test:
- testName: string //This will be displayed by error or fault test in the test log.
- expectedServerName: string //This will be compared with the server name that will be returned by the response.
- expectedServerPort: string //This will be compared with the server port that will be returned by the response.
- tenantId: string //This will be added to the request url instead of #{tenantId}.
- requestParameters?: RequestParameter[] //This is for the request parameters, must be added using RequestParameter list 'or empty list []'.
- requestBody?: any //(optional) This is for the requst body.
- requestHeaders?: object //(optional) This is for the request headers.
- urlAddition?: string //URL addition to be added at the end of the url.
TestObjectList is used to generate new TestObjects based on a given TestObject and to contain the TestObjects as a list and to manage them within it:
- originalTestObject: TestObject //The original TestObject wich will be copied (Only tenantId will be replaced if neccessary).
- startTenantId: string //is the start tenant it wich will be increased based on incrementStep.
- totalTestObjects: //is how many test objects you want to generate.
- fixedTenant: boolean //If you want to increased the startTenantId of the generated TestObjects or use it as-is for all generated objects from the originalTestObject.
- incrementStep: number //how many steps (numbers) do you want to increase the startTenantId per generated object.
- testObjects: TestObject[] //The list that contains all TestObjects.
This object contains the TestObject and the total rounds to know how many times this TestObject has be warmed up before testing.
- testObject: TestObject
- rounds: number
Object to contain if the request succeed or failed and the response.
- succeed: boolean //The result of the api call, if the call succeed or failed with error.
- response?: AxiosResponse<any, any> //The response of the api call.
- error?: any //The error description if the api call failed with error.
Object that contains the attributes and values which being got from the response of the collections url request. These data are used to add a list of TenantAddress in the tests.
- schema: string //Contains the schema name
- name: string //Contains the endpoint of the tenant in the schema
- inCache: boolean
- count: number
- checkPoint: number
- lastOplogId: number
This object contains list of the servers that has been inspected for RAM with lists of each server RAM usage to be plotted.
- [ server: string ]: number[] //The host:port string assigned to the server as a key.
This object contains list of the servers that has been tested for time usage with lists of each server time usage to be logged or plotted.
- [ server: string ]: number[] //The host:port string assigned to the server as a key.