<commit_before>var request = require('request');

var maxLogSize = process.env.MAX_LOG_SIZE;
var apiUrl = process.env.API_URL+"/v1";


class API {
  constructor() {
    this.url = apiUrl;
  }
  createLog() {
    return new Promise((resolve, reject) => {
      request.post(this.url, {}, (e, r, b) => {
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
  showLog(logurl) {
    return new Promise((resolve, reject) => {
      request.get(this.url+"/"+logurl, (e, r, b) => {
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
  createEntry(logid, type, data) {
    return new Promise((resolve, reject) => {
      request.post(this.url+"/"+logid, {"type":type, "data":data}, (e, r, b) => {
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
  editEntry(logid, entryid, type, data) {
   return new Promise((resolve, reject) => {
    request.put(this.url+"/"+logid+"/"+entryid, {"type":type, "data":data}, (e, r, b) => {
      if (e) reject(e);
      else resolve(JSON.parse(b));
    });
   });
  }
  deleteEntry(logid, entryid) {
    return new Promise((resolve, reject) => {
      request.del(this.url+"/"+logid+"/"+entryid, {}, (e, r, b) => {
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
}

class Entry {
  constructor(logid, entry) {
    this.api = new API();
    if (logid) this.logid = logid;
    if (entry) {
      this.id = entry.entryid;
      this.type = entry.type;
      this.data = entry.data;
    }
  }
  create(type, data) {
    return this.api.createEntry(this.logid, type, data).then(entry => {
      this.id = entry.entryid;
      this.type = entry.type;
      this.data = entry.data;
    });
  }
  edit(type, data) {
    return this.api.editEntry(this.logid, this.id, type, data).then(entry => {
      this.type = entry.type;
      this.data = entry.data;
    });
  }
  del() {
    return this.api.deleteEntry(this.logid, this.id)
  }
}

class Log {
  constructor(log) {
    this.api = new API();
    this.entries = [];
    if (log) {
      this.url = log.logurl;
      this.id = log.logid;
    }
  }
  create() {
    return this.api.createLog().then(log => {
      this.url = log.logurl;
      this.id = log.logid;
    });
  }
  show() {
    return this.api.showLog(this.url).then(entries => {
      this.entries = entries.map(e => new Entry(this.id,e));
    });
  }
  addEntry(type, data) {
    var entry = new Entry(this.id);
    return entry.create(type, data).then(entry => {
      this.entries.push(new Entry(this.id, entry));
    });
  }
}

var randomString = function() {
  var crypto = require('crypto')
  , shasum = crypto.createHash('sha1');
  shasum.update(Math.random().toString());
  return shasum.digest('hex');
}

var randomLogSize = function() {
  return getRandomInt(1, maxLogSize);
}

var getRandomInt = function(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

var testAddEntries = function(log, count) {
  return new Promise((resolve, reject) => {
    var entrydata = [];
    for (let i=0; i<count; i++) {
      entrydata.push(randomString());
    }
    //Add entries
    Promise.all(entrydata.map(d => log.addEntry("text",d))).then(function(r) {
      log.show().then(function(r) {
        //check entries & log
        for (let i=0; i<log.entries.length; i++) {
          if (log.entries[i].data != entriesdata[i]) {
            console.log("Some problem in order? Something missing?");
            reject();
          }
        }
        resolve(log);
      });
    });
  });
}

var testEditEntries = function(log) {
  return new Promise((resolve, reject) => {
    var type = "text";
    var data = "foo";
    Promise.all(log.entries.map(e => e.edit(type,data))).then(function() {
      log.show().then(function() {
        for (let i=0; i<log.entries.length; i++) {
          if (log.entries[i].data != data) {
            console.log("Somebody didn't get edited");
            reject();
          }
        }
        resolve(log);
      });
    });
  });
}

var testDeleteEntries = function(log) {
  return new Promise((resolve, reject) => {
    Promise.all(log.entries.map(e => e.del())).then(function() {
      log.show().then(function() {
        if (log.entries.length != 0) {
          console.log("Somebody didn't get deleted");
          reject();
        }
        else resolve();
      });
    });
  });
}

var startTest = function () {
  var logSize = randomLogSize();
  var entrydata = [];
  for (let i=0; i<logSize; i++) {
    entrydata.push(randomString());
  }
  var log = new Log();
  log.create().then(function() {
    testAddEntries(log, logsize).then(testEditEntries).then(testDeleteEntries).then(function() {
      console.log("WORKS for log size: "+logsize+" (logid: "+log.id+", logurl: "+logurl+")");
    }, function(err) {
      console.log("FAILED for log size: "+logsize+" (logid: "+log.id+", logurl: "+logurl+")");
    });
  });
}

setInterval(function(){startTest()}, 1000);<commit_msg>change args to request.post and request.put<commit_after>var request = require('request');

var maxLogSize = process.env.MAX_LOG_SIZE;
var apiUrl = process.env.API_URL+"/v1";


class API {
  constructor() {
    this.url = apiUrl;
  }
  createLog() {
    return new Promise((resolve, reject) => {
      request.post({url:this.url, form:{}}, (e, r, b) => {
        console.log(b);
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
  showLog(logurl) {
    return new Promise((resolve, reject) => {
      request.get(this.url+"/"+logurl, (e, r, b) => {
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
  createEntry(logid, type, data) {
    return new Promise((resolve, reject) => {
      request.post({url: this.url+"/"+logid, form: {"type":type, "data":data}}, (e, r, b) => {
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
  editEntry(logid, entryid, type, data) {
   return new Promise((resolve, reject) => {
    request.put({url: this.url+"/"+logid+"/"+entryid, form: {"type":type, "data":data}}, (e, r, b) => {
      if (e) reject(e);
      else resolve(JSON.parse(b));
    });
   });
  }
  deleteEntry(logid, entryid) {
    return new Promise((resolve, reject) => {
      request.del(this.url+"/"+logid+"/"+entryid, (e, r, b) => {
        if (e) reject(e);
        else resolve(JSON.parse(b));
      });
    });
  }
}

class Entry {
  constructor(logid, entry) {
    this.api = new API();
    if (logid) this.logid = logid;
    if (entry) {
      this.id = entry.entryid;
      this.type = entry.type;
      this.data = entry.data;
    }
  }
  create(type, data) {
    return this.api.createEntry(this.logid, type, data).then(entry => {
      this.id = entry.entryid;
      this.type = entry.type;
      this.data = entry.data;
    });
  }
  edit(type, data) {
    return this.api.editEntry(this.logid, this.id, type, data).then(entry => {
      this.type = entry.type;
      this.data = entry.data;
    });
  }
  del() {
    return this.api.deleteEntry(this.logid, this.id)
  }
}

class Log {
  constructor(log) {
    this.api = new API();
    this.entries = [];
    if (log) {
      this.url = log.logurl;
      this.id = log.logid;
    }
  }
  create() {
    return this.api.createLog().then(log => {
      this.url = log.logurl;
      this.id = log.logid;
    });
  }
  show() {
    return this.api.showLog(this.url).then(entries => {
      this.entries = entries.map(e => new Entry(this.id,e));
    });
  }
  addEntry(type, data) {
    var entry = new Entry(this.id);
    return entry.create(type, data).then(entry => {
      this.entries.push(new Entry(this.id, entry));
    });
  }
}

var randomString = function() {
  var crypto = require('crypto')
  , shasum = crypto.createHash('sha1');
  shasum.update(Math.random().toString());
  return shasum.digest('hex');
}

var randomLogSize = function() {
  return getRandomInt(1, maxLogSize);
}

var getRandomInt = function(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

var testAddEntries = function(log, count) {
  return new Promise((resolve, reject) => {
    var entrydata = [];
    for (let i=0; i<count; i++) {
      entrydata.push(randomString());
    }
    //Add entries
    Promise.all(entrydata.map(d => log.addEntry("text",d))).then(function(r) {
      log.show().then(function(r) {
        //check entries & log
        for (let i=0; i<log.entries.length; i++) {
          if (log.entries[i].data != entriesdata[i]) {
            console.log("Some problem in order? Something missing?");
            reject();
          }
        }
        resolve(log);
      });
    });
  });
}

var testEditEntries = function(log) {
  return new Promise((resolve, reject) => {
    var type = "text";
    var data = "foo";
    Promise.all(log.entries.map(e => e.edit(type,data))).then(function() {
      log.show().then(function() {
        for (let i=0; i<log.entries.length; i++) {
          if (log.entries[i].data != data) {
            console.log("Somebody didn't get edited");
            reject();
          }
        }
        resolve(log);
      });
    });
  });
}

var testDeleteEntries = function(log) {
  return new Promise((resolve, reject) => {
    Promise.all(log.entries.map(e => e.del())).then(function() {
      log.show().then(function() {
        if (log.entries.length != 0) {
          console.log("Somebody didn't get deleted");
          reject();
        }
        else resolve();
      });
    });
  });
}

var startTest = function () {
  var logSize = randomLogSize();
  var log = new Log();
  log.create().then(function() {
    testAddEntries(log, logsize).then(testEditEntries).then(testDeleteEntries).then(function() {
      console.log("WORKS for log size: "+logsize+" (logid: "+log.id+", logurl: "+logurl+")");
    }, function(err) {
      console.log("FAILED for log size: "+logsize+" (logid: "+log.id+", logurl: "+logurl+")");
    });
  });
}

setInterval(function(){startTest()}, 1000);
{'fraction_non_alphanumeric': 0.19126010176593833, 'fraction_numerical': 0.002294722139080116, 'mean_word_length': 2.532064834390416, 'pattern_counts': {'":': 8, '<': 10, '<?xml version=': 0, '>': 47, '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': '576478', 'n_tokens_mistral': 3485, 'n_tokens_neox': 3459, 'n_words': 676}