TESTNG: How to change thread-count dynamically, while running the suite

25 views
Skip to first unread message

Balaraj Dacha

unread,
Mar 15, 2018, 7:22:35 AM3/15/18
to Selenium Users

I am trying to implement parallel running TestNG tests with selenium grid, where grid gets dynamic nodes attached. Based on the number of nodes in the grid I want to increase or decrease the number of threads in the TestNG.

Is it possible if so How?

I have tried following cases.

public class SuiteAlterer implements IAlterSuiteListener {

@Override
public void alter(List<XmlSuite> suites) {
    // TODO Auto-generated method stub
    System.err.println("**Alter is invoked**");
    int count = NodeInfoFromGrid.getNumberOfNodes();//returns number of grid nodes that are free.
    if (count <= 0) {
        return;
    }
    for (XmlSuite suite : suites) {
        suite.setThreadCount(count);
    }
}
}
Above Listener works only once while starting the suite

In the Listener OnStart(ITestContext context) added following statement context.getSuite().getXmlSuite().setThreadCount(NodeInfoFromGrid.getNumberOfNodes());


But TestNG is not honoring above statement.


balraj dacha

unread,
Mar 18, 2018, 12:45:19 AM3/18/18
to Selenium Users

Krishnan Mahadevan

unread,
Mar 19, 2018, 1:04:27 AM3/19/18
to seleniu...@googlegroups.com

TestNG lets you decide the threadpool size only at the beginning of the execution. AFAIK you cannot change the threadpool size once the tests have started.

You should instead consider increasing/decreasing the number of nodes based on the Grid’s new session request queue size.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply-To: <seleniu...@googlegroups.com>
Date: Sunday, March 18, 2018 at 10:15 AM
To: Selenium Users <seleniu...@googlegroups.com>
Subject: [selenium-users] TESTNG: How to change thread-count dynamically, while running the suite

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
selenium-user...@googlegroups.com.
To post to this group, send email to
seleniu...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/selenium-users/00ea7bf1-d809-488f-ab7f-93cd1a67c812%40googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages