Skip to content

Support postDebugTask property #1557

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

Closed
Tracked by #1201
rubensa opened this issue Mar 31, 2023 · 21 comments · Fixed by #1567
Closed
Tracked by #1201

Support postDebugTask property #1557

rubensa opened this issue Mar 31, 2023 · 21 comments · Fixed by #1567
Assignees
Milestone

Comments

@rubensa
Copy link

rubensa commented Mar 31, 2023

Provide support for postLaunchTask (like postDebugTask for launch configurations) property to launch a task at the end of testing.

This attribute should be set to the name of a task specified in tasks.json (in the workspace's .vscode folder).

NOTE: This would be the companion to preLaunchTask.

@jdneo
Copy link
Member

jdneo commented Apr 1, 2023

Makes sense since we have postDebugTask for launch configuration. Would you like to share what kind of task you hope to run after testing?

Another problem I'm thinking is about the naming. Maybe we should call it postDebugTask as well to avoid introducing 'ambiguousness'

@rubensa
Copy link
Author

rubensa commented Apr 3, 2023

No problem with the naming but I don't know why the naming preLaunchTask (launch) and then postDebugTask (debug) in the launch attributes.

In my case, In a multi-root workspaces configuration, for just one workspace folder, I'm running a docker-compose up (for ignite and postgres start) for tests that needs database access. I'd like to automatically call a docker-compose down task to tear down the databases just after the tests for that workspace folder has ended.

NOTE: It's also a pitty that I need to define the corresponding empty tasks in other workspaces for the extension complaining for non existing task on those workspaces (as the java.test.config referencing the preLaunchTask is defined at devcontainer.json level), but this is a different issue.

@jdneo
Copy link
Member

jdneo commented Apr 3, 2023

I don't know why the naming preLaunchTask (launch) and then postDebugTask (debug) in the launch attributes.

I'm confused as well. 😂

Thanks for the information.

@jdneo jdneo changed the title Support postLaunchTask property Support postDebugTask property May 4, 2023
@jdneo jdneo added this to the 0.39.0 milestone May 4, 2023
@jdneo jdneo self-assigned this May 4, 2023
@jdneo jdneo removed the help wanted label May 4, 2023
@jdneo
Copy link
Member

jdneo commented May 10, 2023

@rubensa, I just released a pre-release 0.38.2023051002 containing this feature. Should be available in a few hours.

@rubensa
Copy link
Author

rubensa commented May 10, 2023

Thanks @jdneo
I'll try it!

@rubensa
Copy link
Author

rubensa commented May 10, 2023

@jdneo I tried it and works like a charm 👍

@jdneo
Copy link
Member

jdneo commented May 10, 2023

Good to know, thank you for the update! 😁

@rubensa
Copy link
Author

rubensa commented May 10, 2023

@jdneo Doing some more test I found some weird behavior...

For some settings looks like it works ok but for other it can't find the corresponding postDebugTask.

I have a java.test.config with a postDebugTask Teardown test-local and I get a Could not find the task 'Teardown test-local'.. I double checked that the task label matches but the result is always the same.

I have other java.test.config with a postDebugTask Teardown test-snowflake that is working ok.

@jdneo
Copy link
Member

jdneo commented May 10, 2023

Do you have a sample to reproduce the issue?

Is it caused by scope mismatch? (User/Workspace/Workspace Folder)

@rubensa
Copy link
Author

rubensa commented May 10, 2023

@jdneo some more investigations...

I changed the order that the tasks are defined in tasks.json the one that was working is not working anymore an the one that was not working is working now 😨.

For now I'm using both settings.json and tasks.json defined at .vscode folder level in a VSCode workspace.

@rubensa
Copy link
Author

rubensa commented May 10, 2023

This is the settings.json I'm using

{
  "java.test.config": [
    {
      "name": "test-local",
      "vmArgs": [
        "-Dspring.profiles.active=test-local"
      ],
      "envFile": "${workspaceFolder:data-api}/.devcontainer/.env.local",
      "preLaunchTask": "Setup test-local",
      "postDebugTask": "Teardown test-local"
    },
    {
      "name": "test-snowflake",
      "vmArgs": [
        "-Dspring.profiles.active=test-snowflake"
      ],
      "envFile": "${workspaceFolder:data-api}/.devcontainer/.env.local",
      "preLaunchTask": "Setup test-snowflake",
      "postDebugTask": "Teardown test-snowflake"
    }
  ]
}

and this is the tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Setup test-local",
      "type": "docker-compose",
      "dockerCompose": {
        "projectName": "data-api",
        "up": {
          "detached": true
        },
        "files": [
          "../.devcontainer/docker-compose-test.yml"
        ]
      }
    },
    {
      "label": "Teardown test-local",
      "type": "docker-compose",
      "dockerCompose": {
        "projectName": "data-api",
        "down": {},
        "files": [
          "../.devcontainer/docker-compose-test.yml"
        ]
      }
    },
    {
      "label": "Setup test-snowflake",
      "type": "docker-compose",
      "dockerCompose": {
        "projectName": "data-api",
        "up": {
          "detached": true,
          "services": [
            "ignite-db"
          ]
        },
        "files": [
          "../.devcontainer/docker-compose-test.yml"
        ]
      }
    },
    {
      "label": "Teardown test-snowflake",
      "type": "docker-compose",
      "dockerCompose": {
        "projectName": "data-api",
        "down": {},
        "files": [
          "../.devcontainer/docker-compose-test.yml"
        ]
      }
    }
  ]
}

@jdneo
Copy link
Member

jdneo commented May 10, 2023

Have you defined java.test.defaultConfig?

@rubensa
Copy link
Author

rubensa commented May 10, 2023

Nope, as, If I define that, I can't select which config should be used for the execution (see: #1556).

@jdneo
Copy link
Member

jdneo commented May 10, 2023

Hmm, what the extension does is simply put the configured postDebugTask to the launch configuration and pass it to the debugger. The implementation of postDebugTask support is very similar to preLaunchTask. Are the pre-launch tasks work for the two test configs?

@rubensa
Copy link
Author

rubensa commented May 10, 2023

Yes, both pre-launch tasks are working. The problem is only with post-debug tasks.

@jdneo
Copy link
Member

jdneo commented May 10, 2023

Interesting. What if replacing the current post debug tasks to some very simple ones, like:

"tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "echo Hello"
        },
        {
            "label": "echo2",
            "type": "shell",
            "command": "echo Hello2"
        }
    ]

@rubensa
Copy link
Author

rubensa commented May 10, 2023

It works with that!!

I'm really confused now... Looks like a bug in the docker-compose type of tasks??

@jdneo
Copy link
Member

jdneo commented May 10, 2023

Looks like a bug in the docker-compose type of tasks??

Maybe?? 🤔

@rubensa
Copy link
Author

rubensa commented May 10, 2023

Very curious... If I have one using the type shell and other using the type docker-compose, both works without problem. If I have both of type shell they work too. But if I have both of type docker-compose, only the last one is found.

@jdneo
Copy link
Member

jdneo commented May 10, 2023

If you can reproduce it using normal launch configuration with postDebugTask set, maybe file a ticket to the Docker extension for help?

@rubensa
Copy link
Author

rubensa commented May 10, 2023

I managed to guess that the problem only happens if the docker-compose task definitions are equal (only changes the label).

If I modify, for example, the down content (adding a removeOrphans option in one of them, but not in the other), both tasks are recognized without problem.

Again I'm very confused and surprised here...

Should this be some kind of "optimization" in the vscode-docker extension (as the same with type shell works) that is not working right? 😕

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

Successfully merging a pull request may close this issue.

2 participants