Forum Discussion

MikeLoundes's avatar
MikeLoundes
Contributor
12 years ago

Unable to remove file

Hi

I'm having an issue with some temp files I generate being locked and I'm then unable to remove them unless I close SoapUI

I have some tests which call out to another project file which extracts some data from a backend db and creates some datasinks of csv format for use in the main test

I have the following code which is intended to remove any existing files on an iteration of data driven testing


log.info ' Deleting files'
def CurrentDir = new File(groovyUtils.projectPath).parent
def getPartyDetails = context.expand( '${#Project#GetPartyDetails}' )
def getPartyPhoneDetails = context.expand( '${#Project#GetPartyPhoneDetails}' )
def getPartyEmailDetails = context.expand( '${#Project#GetPartyEmailDetails}' )
def getPartyAddressDetails = context.expand( '${#Project#GetPartyAddressDetails}' )

[new File(CurrentDirStr+getPartyDetails),
new File(CurrentDirStr+getPartyPhoneDetails),
new File(CurrentDirStr+getPartyEmailDetails),
new File(CurrentDirStr+getPartyAddressDetails)].
each{ it.delete() } //delete files

log.info ' Checking files deleted'
assert ! new File(CurrentDirStr+getPartyDetails).exists()
assert ! new File(CurrentDirStr+getPartyPhoneDetails).exists()
assert ! new File(CurrentDirStr+getPartyEmailDetails).exists()
assert ! new File(CurrentDirStr+getPartyAddressDetails).exists()



the issue I'm having is that as the main test iterates through the rows of data the ds's created are not always being removed and I end up with a mix of data in the ds that is then causing failures in my assertions when cross referencing the ds data with service response data

after running the main test If I dip into the script test step that deletes the files and run it I get the error below which shows that the file is not being deleted

Assertion failed: assert ! new File(CurrentDirStr+getPartyDetails).exists() | | | || | | | | || true | | | |SoapUI_DS_PartyDetails.csv | | | C:\Users\Public\Documents\SoapUI\SoapUI_DS_PartyDetails.csv | | C:\Users\Public\Documents\SoapUI\ | C:\Users\Public\Documents\SoapUI\SoapUI_DS_PartyDetails.csv false error at line:


is there a way of forcing a close, file release before I attempt the delete?

thanks
Mike

15 Replies

  • Hi

    the files are created by SoapUI,
    the files should only be in use during an iteration across a data row, I think what is happening is that a datasource accesses the file but does not exhaust it, the test run ends then on subsequent iteration the file cannot be deleted because the ds still has it locked

    at the end of an iteration (i.e. last ds loop or test run completion with either fail or success) files should be released, SoapUI appears to be doing nothing with no tests running but you cant even remove the files manually until SoapUI is closed

    thanks for the pointer to the method

    regards
    Mike
  • Hi,

    I'm not able to reproduce what you are saying. I was able to delete an excel file that was used in a DataSource and DataSource loop after the test case finished without closing SoapUI Pro. Do you have the files that are being used by the DataSource open externally outside of SoapUI Pro? If so, that's probably why they are locked. If the files are being created by SoapUI Pro then that is probably why they are locked the entire time. Please confirm that nothing else is using the files after the test case is complete including any Groovy you may be using.


    Regards,
    Marcus
    SmartBear Support
  • Hiya

    files are created by SoapUI only, and not in use by anything else

    for ref due to the way the service response is returned to control the flow and ensure that all test data is returned as expected I'm iterating across the datasource using groovy as per below,
    the assertion test step ('Verify Data in DS') compares the response from the service request response elements to the content of the datasource
    the datasource uses a csv file that is created from a separate test suite that interrogates the back end db



    def CurrentRow
    def DSRowCount = testRunner.testCase.testSteps['DatasourceToUse'].rowCount
    log.info '## DatasourceToUse rowcount = '+ DSRowCount
    for (i = 1; i<=DSRowCount; i++)
    {
    CurrentRow = testRunner.testCase.testSteps['DatasourceToUse'].currentRow
    CurrentRow = CurrentRow.toString()
    log.info 'DatasourceToUse Row No = ' + CurrentRow
    result = testRunner.runTestStepByName("Verify Data in DS");
    log.info "@@ Verify Data in DS = "+result.getStatus()

    result = testRunner.runTestStepByName("DataSource Loop");
    log.info "@@ DataSource Loop = "+result.getStatus()
    }
  • Hi,

    We do not support custom code solutions as an FYI, that is outside of the support agreement.


    I'm not to sure about the code you are using. It looks like your iterating through the datasource, but calling the datasource loop test step which is suppose to iterate through the datasource and the test steps in between. Seems like your doing double iterations. Anyway, there is a release() method for the DataSource.

    http://www.soapui.org/apidocs/pro/com/e ... ource.html

    Try

    testRunner.testCase.testSteps['DatasourceToUse'].getDataSource().release()


    when your done with the datasource. The datasource maybe locking the files and need to be closed or freed to unlock them.



    Regards,
    Marcus
    SmartBear Support
  • Hiya

    thanks I'll give that a try

    I was using the ds loop to move onto the next row of data, I explicitly put in the test step execution because it wasn't actually being run on the ds loop invocation

    regards
    Mike