Skip to content

libsvm instances during the unit tests are influenced by other coexisting instances and cause test failures #12

@JasonShin

Description

@JasonShin

Context:
While trying to cover tests for WASM loaded SVM's predict, I've encountered an issue of incorrect prediction results between running a test by itself vs running tests in-band.

Problematic test:

it('should predict bodyfat scale dataset using C_SVC and LINEAR', () => {
      const rawData = fs.readFileSync(path.join(__dirname, '../samples/bodyfat_scale.txt'), 'utf-8');
      const data = rawData.split('\n').map((line) => line.split(' ').filter((el) => el));
      const labels = data.map((line) => +line.splice(0, 1)[0]);
      const features = data.map((line) => line.map((el) => +el.split(':')[1]));

      const svm = new SVM({
        type: SVMTypes.C_SVC,
        kernel: KernelTypes.LINEAR,
        epsilon: 0.001,
        quiet: true,
        probabilityEstimates: true,
      });
      return svm.loadWASM().then((loadedSVM) => {
        loadedSVM.train({ samples: features, labels });
        const predResult = loadedSVM.predict({
          samples: [features[0], features[1]],
        });
        loadedSVM.free();
        // TODO: It seems like other tests are influencing the result of this.
        // I don't know why so far, we should figure it out
        expect(predResult).toEqual([1, 1]);
      });
    });

When you run this test on its own, it passes without an issue since the loadedSVM instance is isolated. However, if you run this test in parallel/sequentially along with other tests, the prediction starts to return different values.

We should investigate why this is happening and devise a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions