-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: npe during cleanup incomplete executions
the log file storage request may already be deleted, causing NPE when deleting by execution UUID
- Loading branch information
Showing
2 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...vy/org/rundeck/app/data/providers/logstorage/GormLogFileStorageRequestProviderSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.rundeck.app.data.providers.logstorage | ||
|
||
import grails.testing.gorm.DataTest | ||
import org.rundeck.app.data.model.v1.logstorage.LogFileStorageRequestData | ||
import org.rundeck.app.data.providers.GormExecReportDataProvider | ||
import rundeck.CommandExec | ||
import rundeck.ExecReport | ||
import rundeck.Execution | ||
import rundeck.JobExec | ||
import rundeck.LogFileStorageRequest | ||
import rundeck.PluginStep | ||
import rundeck.Workflow | ||
import spock.lang.Specification | ||
|
||
class GormLogFileStorageRequestProviderSpec extends Specification implements DataTest { | ||
def provider = new GormLogFileStorageRequestProvider() | ||
|
||
def setupSpec() { | ||
mockDomains(Execution, LogFileStorageRequest, Workflow, CommandExec, PluginStep, JobExec) | ||
} | ||
|
||
def "Delete by execid no execution"() { | ||
given: | ||
|
||
def execUuid = UUID.randomUUID().toString() | ||
when: | ||
provider.delete(execUuid) | ||
then: | ||
noExceptionThrown() | ||
} | ||
|
||
def "Delete by execid no request"() { | ||
given: | ||
def execUuid = UUID.randomUUID().toString() | ||
def exec = new Execution( | ||
dateStarted: new Date(), | ||
dateCompleted: null, | ||
user: 'user1', | ||
project: 'test', | ||
serverNodeUUID: null, | ||
outputfilepath: '/tmp/test/logs/blah/1.rdlog', | ||
uuid: execUuid | ||
).save() | ||
|
||
|
||
when: | ||
provider.delete(execUuid) | ||
then: | ||
noExceptionThrown() | ||
} | ||
|
||
def "Delete by execid valid"() { | ||
given: | ||
def execUuid = UUID.randomUUID().toString() | ||
def exec = new Execution( | ||
dateStarted: new Date(), | ||
dateCompleted: null, | ||
user: 'user1', | ||
project: 'test', | ||
serverNodeUUID: null, | ||
outputfilepath: '/tmp/test/logs/blah/1.rdlog', | ||
uuid: execUuid | ||
).save() | ||
|
||
|
||
def request = provider.create( | ||
Mock(LogFileStorageRequestData) { | ||
getExecutionUuid() >> execUuid | ||
getExecutionId() >> exec.id | ||
getPluginName() >> 'test' | ||
getFiletype() >> 'test' | ||
getCompleted() >> false | ||
|
||
} | ||
) | ||
when: | ||
def found = Execution.get(exec.id).logFileStorageRequest | ||
then: | ||
found != null | ||
when: | ||
provider.delete(execUuid) | ||
then: | ||
Execution.get(exec.id).logFileStorageRequest == null | ||
LogFileStorageRequest.get(request.id) == null | ||
noExceptionThrown() | ||
} | ||
} |