Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement infrastructure to check recorded trace #510

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

ivandev0
Copy link
Collaborator

This PR contains changes only about infrastructure. There are no new tests, only the example of how to write one. For now with each rerun we get a new trace (if I did everything right). We need to investigate it.

@ivandev0 ivandev0 force-pushed the kylchik/integration_tests branch from ea27b16 to 29c81c3 Compare February 10, 2025 16:22
@ivandev0 ivandev0 requested a review from eupp February 10, 2025 18:16
@ivandev0 ivandev0 marked this pull request as ready for review February 10, 2025 18:16
ProjectToTest("kotlinx.collections.immutable", "592f05fce02a1ad9e26cc6f3fdb55cdd97910599")
)

fun Project.registerIntegrationTestsTasks() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming to registerIntegrationTestsPrerequisites so that the name matches with the registered gradle task name.

}
}

tasks.register("integrationTestsPrerequisites") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename to traceDebuggerIntegrationTestsPrerequisites?

tasks.register("integrationTestsPrerequisites") {
prerequisite.forEach { dependsOn(it) }
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, consider moving this file into TraceDebuggerTasks.kt since this functionality is related to the trace debugger specifically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed IntegrationTestsTasks file into TraceDebuggerIntegrationTestsTasks. I don't really want to push everything into one big file and it is better to separate test and release stuff.


val isInTraceDebuggerMode = System.getProperty("lincheck.traceDebuggerMode", "false").toBoolean()
private const val traceDebuggerModeProperty = "lincheck.traceDebuggerMode"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention in the Lincheck repo we usually use CAPITAL_CASE for constants.

Assert.assertEquals(goldDataFile.readText(), tmpFile.readText())
} else {
copy(tmpFile, goldDataFile)
Assert.fail("The gold data file was created. Please rerun the test.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fail test in this case. To overwrite the expected test output, let's use a gradle property.
We already have one used for similar purposes in Lincheck representation tests, so we can re-use it here (it is called overwriteRepresentationTestsOutput).
See the links below:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? The test will be failed with Assert.fail. This branch means that golden test data wasn't found and it will be created automatically. It is not exactly overwrite

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, I missed the Assert.fail.

Yet still, not sure that the golden data should be automatically created in this case.
IMO, better have one single mechanism to overwrite golden data (e.g., when special flag is set), and in case when there is no file with golden data just output that file was not found.


@Test
fun `tests contract list GuavaImmutableListTest_list`() {
// runGradleTest(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use @Ignore instead and TODO comment explaining why the test is disabled for now.

import java.io.FileOutputStream
import java.util.*

abstract class AbstractIntegrationTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
abstract class AbstractIntegrationTest {
abstract class AbstractTraceDebuggerIntegrationTest {


import org.junit.Test

class KotlinImmutableCollectionsIntegrationTest: AbstractIntegrationTest() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class KotlinImmutableCollectionsIntegrationTest: AbstractIntegrationTest() {
class KotlinImmutableCollectionsTraceDebuggerIntegrationTest: AbstractTraceDebuggerIntegrationTest() {

* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.jetbrains.kotlinx.lincheck_test.integration
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please move the package to trace_debugger.integration.

@ivandev0
Copy link
Collaborator Author

Thanks for the review! I will fix everything on Monday.

@ivandev0 ivandev0 force-pushed the kylchik/integration_tests branch from 29c81c3 to 3241b60 Compare February 24, 2025 19:08
@ivandev0
Copy link
Collaborator Author

All changes are in fixup commits.

@ivandev0 ivandev0 requested a review from eupp February 24, 2025 19:30
@ivandev0 ivandev0 force-pushed the kylchik/integration_tests branch from 3241b60 to 3b7b9b4 Compare February 27, 2025 11:23
@eupp eupp requested a review from ndkoval February 27, 2025 19:17
@eupp
Copy link
Collaborator

eupp commented Feb 27, 2025

Also added @ndkoval to have a final look before we merge.

@@ -30,6 +30,7 @@ fun Project.registerTraceDebuggerTasks() {

val traceDebuggerFatJar = tasks.register<Jar>("traceDebuggerFatJar") {
archiveBaseName.set("fat-trace-debugger")
archiveVersion.set("SNAPSHOT")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it always be SNAPSHOT? Can we use the default version instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "default version"? If we leave it as is, then the version will be different for each release. It is hard to work with that because we should manually update this version in the plugin.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can obtain the current version of Lincheck from the code, see

internal val lincheckVersion by lazy {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it will not work for the plugin and the plugin has exactly the same logic

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to change the jar name but please do not change the version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is our internal fat jar. It is not published anywhere (yet). We can push it as is and I will create a task to think about how to extract lincheck version for the plugin.

Copy link
Collaborator

@ndkoval ndkoval Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to extract anything, you can just change the JAR name to "lincheck-fat-jar.jar"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that it should not be fat-trace-debugger, this is just Lincheck

protected fun runGradleTest(
testClassName: String,
testMethodName: String,
vararg gradleCommand: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can gradleCommand vary or should it always be jvmTest/test?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also do not use vararg here, as it makes the test code less intuitive

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can gradleCommand vary or should it always be jvmTest/test?

Yes, it can change and it can depend on the project's infra that we are testing

Let's also do not use vararg here, as it makes the test code less intuitive

Do you propose to use an array here? Or do you mean to pass it as comma-separated string and parse later? I would like to keep it flexible to allow running multiple commands

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if you think this is better, no problem.

@Ignore
@Test
fun `tests contract list GuavaImmutableListTest_list`() {
runGradleTest(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please always add argument names

}

// TODO decide how to test: with gold data or run twice?
val goldDataFile = File(getGolderDataPathFor(testClassName, testMethodName))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Lincheck, we use the "expected output" term. Please use it here as well for consistency.


@Ignore
@Test
fun `tests contract list GuavaImmutableListTest_list`() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where can I find the expected output file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add an example

import java.io.FileOutputStream
import java.util.*

abstract class AbstractTraceDebuggerIntegrationTest {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's run these tests only in the trace debugger mode

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are running these tests in this mode, please check buildGradleInitScriptToDumpTrace

val jvmTest = named<Test>("jvmTest") {
dependsOn(traceDebuggerIntegrationTestsPrerequisites)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a separate source set and a separate task for integration tests for Trace Debugger, and perform all the related logic only in the trace debugger mode

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it separately for every trace debugger test. I will create a ticket for that

@ivandev0 ivandev0 force-pushed the kylchik/integration_tests branch from 3b7b9b4 to ad95102 Compare March 3, 2025 12:46
@ivandev0 ivandev0 requested a review from ndkoval March 3, 2025 12:47
@ndkoval
Copy link
Collaborator

ndkoval commented Mar 4, 2025

@ivandev0 can we please use the same human-readable output format as we use in other trace representation tests?

@ivandev0
Copy link
Collaborator Author

ivandev0 commented Mar 4, 2025

@ivandev0 can we please use the same human-readable output format as we use in other trace representation tests?

Can you please point me where to look?

@ndkoval
Copy link
Collaborator

ndkoval commented Mar 4, 2025

I guess you need the appendTrace function, but please take a look at any representation test as well, to check whether something else is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants