Updation of Method Invocation Count for concurrent + longitivity tests

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Updation of Method Invocation Count for concurrent + longitivity tests

RAMA RAJESWARI
Hi All,

I am using testng 6.8.13 and i see an issue with the fashion in which Method Invocation Count gets updated.

I am trying to run a concurrency + longitivity test using testng. Test should run on 2 set of input data for 7 iterations.
I was under the understanding that the invocation count should be maintained per user/input data (ThreadLocal), however i see that its a continuously generated number.

Here is my sample program:

import java.io.IOException;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class testAnno {
    @BeforeSuite
    void testBeforeSuite() {
        System.out.println(" this is before suite test 1 **");
    }

    private static String testName;

    @BeforeClass
    public void setUp(ITestContext context) throws IOException {
        testName = context.getAllTestMethods()[0].getMethodName();
    }

    @Test(invocationCount = 7, dataProvider = "dp")
    public void testt1(String x, String y, ITestContext context) {
        String tid = Thread.currentThread().getName() + "_"
                + context.getAllTestMethods()[0].getCurrentInvocationCount();
        System.out.println("the invocation count with thread id is " + tid);
    }

    @DataProvider(parallel = true, name = "dp")
    Object[][] dp() {
        Object[][] obj = new Object[2][2];
        obj[0][0] = "user1";
        obj[0][1] = "password1";
        obj[1][0] = "user2";
        obj[1][1] = "password2";

        return obj;
    }

}

And here goes the output:

 this is before suite test 1 **
the invocation count with thread id is PoolService-0_0
the invocation count with thread id is PoolService-1_1
the invocation count with thread id is PoolService-0_2
the invocation count with thread id is PoolService-1_3
the invocation count with thread id is PoolService-1_4
the invocation count with thread id is PoolService-0_5
the invocation count with thread id is PoolService-0_6
the invocation count with thread id is PoolService-1_7
the invocation count with thread id is PoolService-0_8
the invocation count with thread id is PoolService-1_9
the invocation count with thread id is PoolService-1_10
the invocation count with thread id is PoolService-0_11
the invocation count with thread id is PoolService-1_12
the invocation count with thread id is PoolService-0_13

===============================================
Default suite
Total tests run: 14, Failures: 0, Skips: 0
===============================================


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Updation of Method Invocation Count for concurrent + longitivity tests

Krishnan Mahadevan

The latest released version of TestNG is 6.14.3

 

What you are seeing is not a continuously generated number. Its basically :

 

Invocation Count * Number of rows as returned by the data provider.

For a particular @Test method. Since you are also running your data provider in parallel, if you run the same test in the latest version of TestNG, you would see even values (and not odd values).

 

If you would basically like to do this count, why not just maintain a counter locally in your test ?

 

 

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: <[hidden email]>
Date: Wednesday, March 28, 2018 at 7:30 PM
To: testng-users <[hidden email]>
Subject: [testng-users] Updation of Method Invocation Count for concurrent + longitivity tests

 

Hi All,

I am using testng 6.8.13 and i see an issue with the fashion in which Method Invocation Count gets updated.

I am trying to run a concurrency + longitivity test using testng. Test should run on 2 set of input data for 7 iterations.
I was under the understanding that the invocation count should be maintained per user/input data (ThreadLocal), however i see that its a continuously generated number.

Here is my sample program:

import java.io.IOException;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class testAnno {
    @BeforeSuite
    void testBeforeSuite() {
        System.out.println(" this is before suite test 1 **");
    }

    private static String testName;

    @BeforeClass
    public void setUp(ITestContext context) throws IOException {
        testName = context.getAllTestMethods()[0].getMethodName();
    }

    @Test(invocationCount = 7, dataProvider = "dp")
    public void testt1(String x, String y, ITestContext context) {
        String tid = Thread.currentThread().getName() + "_"
                + context.getAllTestMethods()[0].getCurrentInvocationCount();
        System.out.println("the invocation count with thread id is " + tid);
    }

    @DataProvider(parallel = true, name = "dp")
    Object[][] dp() {
        Object[][] obj = new Object[2][2];
        obj[0][0] = "user1";
        obj[0][1] = "password1";
        obj[1][0] = "user2";
        obj[1][1] = "password2";

        return obj;
    }

}

And here goes the output:

 this is before suite test 1 **
the invocation count with thread id is PoolService-0_0
the invocation count with thread id is PoolService-1_1
the invocation count with thread id is PoolService-0_2
the invocation count with thread id is PoolService-1_3
the invocation count with thread id is PoolService-1_4
the invocation count with thread id is PoolService-0_5
the invocation count with thread id is PoolService-0_6
the invocation count with thread id is PoolService-1_7
the invocation count with thread id is PoolService-0_8
the invocation count with thread id is PoolService-1_9
the invocation count with thread id is PoolService-1_10
the invocation count with thread id is PoolService-0_11
the invocation count with thread id is PoolService-1_12
the invocation count with thread id is PoolService-0_13

===============================================
Default suite
Total tests run: 14, Failures: 0, Skips: 0
===============================================

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[hidden email].
To post to this group, send email to
[hidden email].
Visit this group at
https://groups.google.com/group/testng-users.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.