0
votes

I have a Test plan with several thread groups that write summary report results in the same csv file hosted in a server, this works fine using a networkdrive (z:) and changing jmeter.properties -> resultcollector.action_if_file_exists=APPEND.

Finally I have a tearDown Thread Group that insert the csv data into a sql server (the previous used networkdrive is hosted in this server in c:\jmeter\results.csv) and then it deletes the csv. The case is when I run the test plan full I always have this error: "Cannot bulk load because the file "c:\jmeter\results.csv" could not be opened. Operating system error code 32"

The strange thing is that if I start the tearDown Thread Group alone it works fine, it makes the bulk insert in sql server and then it deletes de csv.

I started 2 days ago with Jmeter, so I'm sure I am misunderstanding something :S

Summary Report Config

JDBC Request

BeanShell PostProcessor that deletes csv

Test plan Structure

1

1 Answers

0
votes

It happens because Summary Report (as well as other listeners) keep the file(s) open until test ends so you need to trigger this "close" event somehow.

Since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting therefore replace this Beanshell PostProcessor with the JSR223 PostProcessor and use the following code:

import org.apache.jmeter.reporters.ResultCollector
import org.apache.jorphan.collections.SearchByClass


def engine = engine = ctx.getEngine()
def test = engine.getClass().getDeclaredField('test')

test.setAccessible(true)

def testPlanTree = test.get(engine)

SearchByClass<ResultCollector> listenerSearch = new SearchByClass<>(ResultCollector.class)
testPlanTree.traverse(listenerSearch)
Collection<ResultCollector> listeners = listenerSearch.getSearchResults()

listeners.each { listener ->
    def files = listener.files
    files.each { file ->
        file.value.pw.close()
    }
}

new File('z:/result.csv').delete()

More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It