<commit_before>@TestOn('vm')
library engine_test;

import 'dart:convert';

import 'package:test/test.dart';
import 'package:web_socket_channel/io.dart';

import 'package:whisper/src/engine/engine.dart';

main() {
  group('Socket server', () {
    Engine engine;
    IOWebSocketChannel ioWebSocketChannel;

    setUpAll(() async {
      engine = new Engine();
      await engine.socket.powerUp(ip: 'localhost', port: 8181);
    });

    setUp(() async {
      ioWebSocketChannel =
          await new IOWebSocketChannel.connect('ws://localhost:8181');
    });

    test('can register clients', () async {
      ioWebSocketChannel.stream
          .listen(expectAsync((String messageFromSocketEngine) {
        Map data = JSON.decode(messageFromSocketEngine);
        expect(data['Message'], equals('ClientConnected'));
        expect(data['OnlineClientsCount'], equals(1));
      }, count: 1));

      ioWebSocketChannel.sink.close();
    });

    test('can get message', () async {
      ioWebSocketChannel.stream.listen(expectAsync((String details) {
        Map data = JSON.decode(details);

        if (data['Message'] == 'ClientConnected') {
          ioWebSocketChannel.sink
              .add(JSON.encode({'Message': 'Test message from client'}));
        }

        if (data['Message'] != 'ClientConnected') {
          expect(data['Message'], equals('MessageReceived'));

          ioWebSocketChannel.sink.close();
        }
      }, count: 2));
    });

    test('can send message', () async {
      IOWebSocketChannel secondIoWebSocketChannel =
          await new IOWebSocketChannel.connect('ws://localhost:8181');

      secondIoWebSocketChannel.stream.listen(expectAsync((String details) {
        Map data = JSON.decode(details);
        if (data['Message'] == 'ClientConnected' &&
            data['OnlineClientsCount'] == 2) {
          secondIoWebSocketChannel.sink.add(JSON.encode({
            'Message': 'WriteToAllClients',
            'Details': {'ForAllClientsMessage': 'Hello from second client'}
          }));
        }

        if (data['From'] == 'SocketEngine') {
          expect(data['Message'], equals('MessageReceived'));
          secondIoWebSocketChannel.sink.close();
        }
      }, count: 2, max: 3));

      ioWebSocketChannel.stream.listen(expectAsync((String details) async {
        Map data = JSON.decode(details);
        if (data['Message'] != 'ClientDisconnected' &&
            data['Message'] != 'ClientConnected') {
          expect(data['Details']['ForAllClientsMessage'],
              equals('Hello from second client'));
          ioWebSocketChannel.sink.close();
        }
      }, count: 3, max: 4));
    });
  });
}
<commit_msg>Skip some socket test<commit_after>@TestOn('vm')
library engine_test;

import 'dart:convert';

import 'package:test/test.dart';
import 'package:web_socket_channel/io.dart';

import 'package:whisper/src/engine/engine.dart';

main() {
  group('Socket server', () {
    Engine engine;
    IOWebSocketChannel ioWebSocketChannel;

    setUpAll(() async {
      engine = new Engine();
      await engine.socket.powerUp(ip: 'localhost', port: 8181);
    });

    setUp(() async {
      ioWebSocketChannel =
          await new IOWebSocketChannel.connect('ws://localhost:8181');
    });

    test('can register clients', () async {
      ioWebSocketChannel.stream
          .listen(expectAsync((String messageFromSocketEngine) {
        Map data = JSON.decode(messageFromSocketEngine);
        expect(data['Message'], equals('ClientConnected'));
        expect(data['OnlineClientsCount'], equals(1));
      }, count: 1));

      ioWebSocketChannel.sink.close();
    });

    test('can get message', () async {
      ioWebSocketChannel.stream.listen(expectAsync((String details) {
        Map data = JSON.decode(details);

        if (data['Message'] == 'ClientConnected') {
          ioWebSocketChannel.sink
              .add(JSON.encode({'Message': 'Test message from client'}));
        }

        if (data['Message'] != 'ClientConnected') {
          expect(data['Message'], equals('MessageReceived'));

          ioWebSocketChannel.sink.close();
        }
      }, count: 2));
    });

    test('can send message', () async {
      IOWebSocketChannel secondIoWebSocketChannel =
          await new IOWebSocketChannel.connect('ws://localhost:8181');

      secondIoWebSocketChannel.stream.listen(expectAsync((String details) {
        Map data = JSON.decode(details);
        if (data['Message'] == 'ClientConnected' &&
            data['OnlineClientsCount'] == 2) {
          secondIoWebSocketChannel.sink.add(JSON.encode({
            'Message': 'WriteToAllClients',
            'Details': {'ForAllClientsMessage': 'Hello from second client'}
          }));
        }

        if (data['From'] == 'SocketEngine') {
          expect(data['Message'], equals('MessageReceived'));
          secondIoWebSocketChannel.sink.close();
        }
      }, count: 2, max: 3));

      ioWebSocketChannel.stream.listen(expectAsync((String details) async {
        Map data = JSON.decode(details);
        if (data['Message'] != 'ClientDisconnected' &&
            data['Message'] != 'ClientConnected') {
          expect(data['Details']['ForAllClientsMessage'],
              equals('Hello from second client'));
          ioWebSocketChannel.sink.close();
        }
      }, count: 3, max: 4));
    }, skip: 'it\'s not needed for this socket');
  });
}

{'fraction_non_alphanumeric': 0.15081120943952803, 'fraction_numerical': 0.007374631268436578, 'mean_word_length': 2.8366336633663365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6512694', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1505, 'n_words': 282}